Home >Database >Mysql Tutorial >oracle中格式化SYS_GUID()成为标准格式 用法

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

WBOY
WBOYOriginal
2016-06-07 17:46:192663browse

本文章简单的介绍了一篇关于oracle中格式化SYS_GUID()成为标准格式 用法,有需要学习的同事可以看看哦。

本文章简单的介绍了一篇关于oracle中格式化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)
  sys_guid() from dual connect by rownum 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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn