I'd like to format the result of the sys_guid() function such as proposed in this answer
select regexp_replace(rawtohex(sys_guid())
, '([A-F0-9]{8})([A-F0-9]{4})([A-F0-9]{4})([A-F0-9]{4})([A-F0-9]{12})'
, '\1-\2-\3-\4-\5')
as FORMATTED_GUID
from dual
From performance reasons I'd like to avoid the usage of regexp_replace (as I process large number of records).
My scenario can be simplified to this use case:
select rawtohex(sys_guid()) GUID
from dual connect by level <= 2;
Obviously I can't use substr and concatenation as each SUBSTR would process a different SYS_GUID. I would also like to stay in SQL, without a context switch to PL/SQL function.
Any idea how to format string in SQL similar to date or number using a mask:
to_char(rawtohex(sys_guid(),'CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC') /* note, this is clear illegal */