在DB2里,用SQL怎么生成UUID?有没有相关函数?
------解决方案--------------------------------------------------------
收藏的自定义生成固定位数随机数的方法
- SQL code
CREATE FUNCTION DB2INST1.F_RANDOM ("IN_LENGTH" INTEGER ) RETURNS INTEGER SPECIFIC DB2INST1.F_RANDOM LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA STATIC DISPATCH CALLED ON NULL INPUT EXTERNAL ACTION INHERIT SPECIAL REGISTERS BEGIN atomic declare v_newLength INTEGER; declare v_random INTEGER; declare v_length INTEGER; declare v_index INTEGER; declare out_result VARCHAR(30); IF in_length > 30 THEN RETURN 0; END IF; SET v_random = INTEGER(RAND()*POWER(10,in_length)); SET v_length = in_length - LENGTH(RTRIM(CHAR(v_random))); SET v_index = 1; SET out_result = CHAR(v_random); WHILE v_index <= v_length DO SET out_result = CONCAT('8',out_result);--位数不够,前面补8 SET v_index = v_index + 1; END WHILE; SET v_random = INTEGER(out_result); RETURN v_random; END;
------解决方案--------------------------------------------------------
http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.IBMDS.doc_5.2/admin_gd367.htm
http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?topic=/com.ibm.db2.udb.admin.doc/doc/r0000809.htm