一聚教程网:一个值得你收藏的教程网站

热门教程

oracle中格式化SYS_GUID()成为标准格式 用法

时间:2022-06-29 10:08:10 编辑:袖梨 来源:一聚教程网

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})',
                      '4321-65-87-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

热门栏目