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