Last active
June 17, 2024 12:14
-
-
Save MartinMatta/3c4b66c1ea38160a5f87523dfe921a0e to your computer and use it in GitHub Desktop.
UUID generator in PL/SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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