Skip to content

Instantly share code, notes, and snippets.

@MartinMatta
Last active June 17, 2024 12:14
Show Gist options
  • Select an option

  • Save MartinMatta/3c4b66c1ea38160a5f87523dfe921a0e to your computer and use it in GitHub Desktop.

Select an option

Save MartinMatta/3c4b66c1ea38160a5f87523dfe921a0e to your computer and use it in GitHub Desktop.
UUID generator in PL/SQL
DECLARE
FUNCTION GET_UUID RETURN VARCHAR2 IS
RANDOM_ID VARCHAR2(100);
BEGIN
WITH RANDOM_STR AS (
SELECT LOWER(STANDARD_HASH(DBMS_RANDOM.STRING('a', 10), 'MD5')) STR
FROM DUAL
)
SELECT SUBSTR(STR, 1, 8 ) || '-' ||
SUBSTR(STR, 9, 4 ) || '-' ||
SUBSTR(STR, 13, 4 ) || '-' ||
SUBSTR(STR, 17, 4 ) || '-' ||
SUBSTR(STR, 21 ) INTO RANDOM_ID
FROM RANDOM_STR;
RETURN(RANDOM_ID);
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(GET_UUID);
DBMS_OUTPUT.PUT_LINE(GET_UUID);
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment