Because I am using. NET C # for development, I usually use SQL Server's NEWID () function to generate the ID of the data.
Guid.NewGuid () is also easy to use in the C # language. The ToString () method to generate the same ID as the format.
Now that the database has been replaced with Oracle, there is no such function that can be easily called, but Oracle has a function sys_guid ().
Returns a string of binary data that can be converted to a varchar type by casting to the same ID that is generated by the NEWID () method in SQL Server.
We just have to do it again, insert a few '-' symbols on it.
Make a function, so that it is convenient to call:
CREATE OR REPLACE FUNCTION NEWIDRETURN VARCHAR2 isGUIDVARCHAR2( +);BEGINGUID:=Sys_guid (); RETURN '{' ||SUBSTR (GUID,1,8) ||'-'||SUBSTR (GUID,9,4) ||'-'||SUBSTR (GUID, -,4) ||'-'||SUBSTR (GUID, -,4) ||'-'||SUBSTR (GUID, +, A) ||'}';END NEWID;
You can then use the same as in SQL Server:
SELECT NEWID as from DUAL -- The returned result is a value like this: {1b869dee-bf1a-0d8c-e050-bd0a9e806700}
Implementing the NEWID () function function in the SQL Server database in an Oracle database