Last active
October 4, 2016 14:55
-
-
Save phpdave/d261c59b8901b5ab8c7d4fdd99d7ecc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE SEQUENCE MYLIB.MYAUTO_INCREMENTING_SEQ | |
AS BIGINT | |
START WITH 1 | |
INCREMENT BY 1 | |
NO ORDER | |
NO CYCLE | |
NO MINVALUE | |
NO MAXVALUE | |
CACHE 20; | |
CREATE OR REPLACE TRIGGER FILESRDB.TESTDDS_MAINTAIN | |
BEFORE INSERT ON FILESRDB.TESTDDS | |
REFERENCING NEW AS N FOR EACH ROW | |
BEGIN ATOMIC | |
SET n.tstid = NEXT VALUE FOR MYLIB.MYAUTO_INCREMENTING_SE; | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE TRIGGER FILESRDB.TESTDDS_MAINTAIN | |
BEFORE INSERT ON FILESRDB.TESTDDS | |
REFERENCING NEW AS N FOR EACH ROW | |
BEGIN ATOMIC | |
DECLARE V_NEXT_ID CHAR(8) DEFAULT ''; | |
DECLARE CURSOR_NEXT_ID CURSOR FOR | |
SELECT COALESCE(MAX(tstid), 0) + 1 FROM FILESRDB.TESTDDS; | |
OPEN CURSOR_NEXT_ID ; | |
FETCH CURSOR_NEXT_ID INTO V_NEXT_ID; | |
SET n.tstid = V_NEXT_ID; | |
CLOSE CURSOR_NEXT_ID; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment