格式化SYS_GUID()成为标准格式
格式化SYS_GUID()
Oracle里面用RAW(16)保存SYS_GUID()的结果,不过字节顺序(byte order)和标准的GUID不同。如下
标准GUID: 265B113F-0E9D-F44D-A9D4-18BC4D3E836C
RAW(16) : 3F115B26 9D0E 4DF4 A9D4 18BC4D3E836C (实际没有空格,这里是为了显示方便)
为了方便查看,可以用正则表达式进行简单的转换
create table t(x raw(16));
insert into t(x)
select sys_guid() from dual connect by rownum <=5;
commit;
select x,
regexp_replace(x,
'(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})(.{4})',
'\4\3\2\1-\6\5-\8\7-\9-') as fmt_x
from t;
X FMT_X
-------------------------------- --------------------------------------------------------------------------------
B5D8E10BB3BCC595E040007F01000F49 0BE1D8B5-BCB3-95C5-E040-007F01000F49
B5D8E10BB3BDC595E040007F01000F49 0BE1D8B5-BDB3-95C5-E040-007F01000F49
B5D8E10BB3BEC595E040007F01000F49 0BE1D8B5-BEB3-95C5-E040-007F01000F49
B5D8E10BB3BFC595E040007F01000F49 0BE1D8B5-BFB3-95C5-E040-007F01000F49
B5D8E10BB3C0C595E040007F01000F49 0BE1D8B5-C0B3-95C5-E040-007F01000F49
PS:
本文参考了这个小工具 http://www.robobunny.com/cgi-bin/guid
posted on 2012-01-06 16:49 wait4friend 阅读(749) 评论(0) 编辑 收藏 举报