背景
在业务产品中,存在使用 oracle 移植过来的sql语句。它们使用rawtohex(sys_guid()) 函数或者guid字符串。lightdb 23.4 版本对此进行了支持。
lightdb 支持函数 rawtohex(sys_guid()) / rawtohex(uuid)
在 lightdb 23.4 以后,lightdb 支持 Oracle 的 rawtohex(uuid) 函数将 guid/uuid 转换成16进制数对应的字符。rawtohex(uuid) 函数为函数 rawtohex(raw),rawtohex(text) 的重载函数。rawtohex(uuid) 函数返回类型为 VARCHAR2 ,其中 uuid 类型为16个字节。每个字节由两个十六进制数字表示。此函数将原始值转换为一个包含其十六进制表示的字符值。在 lightdb23.4 之前, lightdb 执行rawtohex(uuid) 报如下错误 ERROR: syntax error at or near “rawtohex”。示例如下
1.使用强转获取uuid
SELECT * FROM rawtohex('0123456789abcdef0123456789abcdef'::uuid);
rawtohex
0123456789abcdef0123456789abcdef
(1 row)
2.使用sys_guid()获取uuid
select rawtohex(sys_guid());
rawtohex
6466c654a5dc4755902b70d0e6ea6eb6
(1 row)