Implementing the NEWID () function function in the SQL Server database in an Oracle database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.