Oracle中生成uuid的方法 下载LOFTER客户端 在Oracle SQL 提供了一个生成uuid的函数sys_guid: http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions187.htm#i79194 http://en.wikipedia.org/wiki/Universally_unique_identifier SQL> select sys_guid() from dual ; SYS_GUID() -------------------------------- A8F662B86E7413FEE040970A437C6BD7 但该函数如下问题: 1.返回类型为RAW 2.没有- (dash)分隔符 3.返回的字母大写 为了使产生的uuid符合rfc 4122的标准(http://tools.ietf.org/html/rfc4122) 创建函数如下,测试通过。 CREATE OR REPLACE FUNCTION get_uuid RETURN VARCHAR IS guid VARCHAR (50); BEGIN guid := lower(RAWTOHEX(sys_guid())); RETURN substr(guid,1,8)||'-'||substr(guid,9,4)||'-'||substr(guid,13,4)||'-'||substr(guid,17,4)||'-'||substr(guid,21,12); END get_uuid; SQL> select get_uuid from dual ; GET_UUID -------------------------------------------------------------------------------- a8f662b8-6e7a-13fe-e040-970a437c6bd7 SQL> / GET_UUID -------------------------------------------------------------------------------- a8f662b8-6e7b-13fe-e040-970a437c6bd7 SQL> / GET_UUID -------------------------------------------------------------------------------- a8f662b8-6e7c-13fe-e040-970a437c6bd7
来源:https://www.cnblogs.com/qmfsun/p/4575484.html