Oracle中生成uuid的方法 下载LOFTER客户端 在Oracle SQL 提供了一个生成uuid的函数sys_guid:http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions187.htm#i79194http://en.wikipedia.org/wiki/Universally_unique_identifierSQL> select sys_guid() from dual ;SYS_GUID()--------------------------------A8F662B86E7413FEE040970A437C6BD7但该函数如下问题: 1.返回类型为RAW 2.没有- (dash)分隔符 3.返回的字母大写为了使产生的uuid符合rfc 4122的标准(http://tools.ietf.org/html/rfc4122)创建函数如下,测试通过。CREATE OR REPLACEFUNCTION get_uuidRETURN VARCHARISguid VARCHAR (50);BEGINguid := lower(RAWTOHEX(sys_guid()));RETURNsubstr(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-970a437c6bd7SQL> /GET_UUID--------------------------------------------------------------------------------a8f662b8-6e7b-13fe-e040-970a437c6bd7SQL> /GET_UUID--------------------------------------------------------------------------------a8f662b8-6e7c-13fe-e040-970a437c6bd7