Oracle generated UUID summary

UUID generated using sys_guid () function can be

select sys_guid() from dual;

But the acquisition of the above type is RAW, we usually need is a VARCHAR2 string

select lower(RAWTOHEX(sys_guid())) from dual;

Use this to get to lowercase and is the UUID string

If the application is in a stored procedure, you can create a FUNCTION returns the corresponding UUID, we call convenience

--返回不带'-'的UUID
CREATE OR REPLACE FUNCTION get_uuid RETURN VARCHAR IS
  guid VARCHAR(50);
BEGIN
  guid := lower(RAWTOHEX(sys_guid()));
  RETURN guid;
END get_uuid;
--返回带'-'的UUID
CREATE OR REPLACE FUNCTION get_uuid RETURN VARCHAR IS
  guid VARCHAR(50);
BEGIN
  guid := lower(RAWTOHEX(sys_guid()));
  RETURN substr(guid, 1, 8) || '-' || 
         substr(guid, 9, 4) || '-' || 
         substr(guid, 13,4) || '-' || 
         substr(guid, 17,4) || '-' || 
         substr(guid, 21,12);
END get_uuid;

 

Guess you like

Origin www.cnblogs.com/teddy-bear/p/11796364.html