DB2 defining UUID

Source: Internet
Author: User

Many databases have provided the Uuid/guid function, but DB2 did not, do not know what IBM think, fortunately DB2 provides a custom function interface, and support Java, since no, provide Java custom function, also good, write a UUID in Java too easy, a few lines of code, Let's get a uuid on my own.

1. Java class

1 ImportJava.util.UUID;2 ImportCOM.ibm.db2.app.UDF;3 4  Public classUdfuuidextendsudf{5      Public StaticString uuid () {6UUID UUID =Uuid.randomuuid ();7         //Remove the middle divider8String uid = uuid.tostring (). ReplaceAll ("-", "" ");9         returnuid;Ten     } One}


2. Put the Java class in the DB2 Library directory and put it under ibm\sqllib\function.
3. Compile with the JDK of the DB2,
Ibm\sqllib\java\jkd\bin\javac Udfuuid.java
4. Registration function

1 Drop functionuuid;2 Create functionuuid ()3     returns Char( +)4 fenced5 Variant6 No SQL7 language Java8 parameter style java9External name'Udfuuid!uuid';


5. Use to see

Values (UUID ());


You can use it later if you want to use it.

DB2 defining UUID

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.