全部博文(6)
2012年(6)
分类: DB2/Informix
2012-05-29 14:09:25
点击(此处)折叠或打开
点击(此处)折叠或打开
- CREATE SEQUENCE seq1 AS INTEGER;
- VALUES NEXT VALUE FOR seq1;
- 1
- -----------
- 1
- 1 record(s) selected.
点击(此处)折叠或打开
- VALUES GENERATE_UNIQUE();
- 1
- -----------------------------
- x'20101110052559155343000000'
- 1 record(s) selected.
点击(此处)折叠或打开
- import java.util.UUID; // for UUID class
- public class UUIDUDF
- {
- public static String randomUUID()
- {
- return UUID.randomUUID().toString();
- }
- }
点击(此处)折叠或打开
- javac UUIDUDF.java
点击(此处)折叠或打开
- jar cvf UUIDUDF.jar UUIDUDF.class
点击(此处)折叠或打开
- db2 -t
点击(此处)折叠或打开
- connect to
You may want to move the JAR file to a safe place and adjust the path above accordingly.点击(此处)折叠或打开
- call sqlj.install_jar('file:.\UUIDUDF.jar', 'UUIDUDFJAR')
点击(此处)折叠或打开
- CREATE OR REPLACE FUNCTION RANDOMUUID()
- RETURNS VARCHAR(36)
- LANGUAGE JAVA
- PARAMETER STYLE JAVA
- NOT DETERMINISTIC NO EXTERNAL ACTION NO SQL
- EXTERNAL NAME 'UUIDUDFJAR:UUIDUDF.randomUUID' ;
What you see is the generally accepted pretty-printed form of UUIDs.点击(此处)折叠或打开
- VALUES RANDOMUUID();
- 1
- ------------------------------------
- aa0058ed-bcca-4ead-a22f-b648ccb66787
- 1 record(s) selected.
This is a 16 byte long VARCHAR FOR BIT DATA.点击(此处)折叠或打开
- VALUES VARCHAR_BIT_FORMAT(RANDOMUUID(), 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
- 1
- -------------------------------------------------------------------------------------
- x'57E71F89F093428DB696A9FEB6785853'
- 1 record(s) selected.
点击(此处)折叠或打开
- CREATE OR REPLACE FUNCTION SYS_GUID()
- RETURNS CHAR(16) FOR BIT DATA
- CONTAINS SQL NOT DETERMINISTIC NO EXTERNAL ACTION
- RETURN VARCHAR_BIT_FORMAT(RANDOMUUID(), 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
- VALUES SYS_GUID();
- 1
- -----------------------------------
- x'A6F0F1FFF93B4CF8A9C4E990774D9B70'
- 1 record(s) selected.
点击(此处)折叠或打开
- CREATE TABLE license(key CHAR(16) FOR BIT DATA NOT NULL PRIMARY KEY,
- customername VARCHAR(20),
- product VARCHAR(20));
- CREATE OR REPLACE TRIGGER license_bi BEFORE INSERT ON license
- REFERENCING NEW AS n FOR EACH ROW
- SET n.key = SYS_GUID();
- SELECT key FROM NEW TABLE(INSERT INTO license(customername, product) VALUES('Oracle', 'DB2'));
- KEY
- -----------------------------------
- x'A944FBAA5611459EBB9C7FCEC7F65FDE'
- 1 record(s) selected.