Last active
October 27, 2016 14:20
-
-
Save phpdave/f2b8835cc6e6d4a7fd0bc8a40ba041e4 to your computer and use it in GitHub Desktop.
Instead of Trigger for IBM i DB2
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
/* Creating view MYLIB.ACCOUNTVIEW */ | |
CREATE OR REPLACE VIEW MYLIB.ACCOUNTVIEW AS | |
SELECT | |
CMPNME AS COMPANY_NAME, | |
ADDR AS COMPANY_ADDRESS | |
FROM MYLIB.ACCTPF; | |
/* Setting system view name to ACCOUNTVIE for MYLIB.ACCOUNTVIEW */ | |
RENAME MYLIB.ACCOUNTVIEW TO SYSTEM NAME ACCOUNTVIE; | |
/* Setting label text for MYLIB.ACCOUNTVIEW */ | |
LABEL ON TABLE MYLIB.ACCOUNTVIEW IS 'SQL View of ACCTPF' ; |
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
/* Creating SQL trigger MYLIB.ACCTADDTRG */ | |
CREATE OR REPLACE TRIGGER MYLIB.ACCTADDTRG | |
INSTEAD OF INSERT ON MYLIB.ACCOUNTVIEW | |
REFERENCING NEW NewViewRow | |
FOR EACH ROW MODE DB2SQL | |
BEGIN ATOMIC | |
INSERT INTO MYLIB.ACCTPF (CMPNME, | |
ADDR) | |
VALUES (COALESCE(NewViewRow.COMPANY_NAME,' '), | |
COALESCE(NewViewRow.COMPANY_ADDRESS,' ')); | |
END; | |
/* Setting label text for MYLIB.ACCTADDTRG */ | |
LABEL ON TRIGGER MYLIB.ACCTADDTRG IS | |
'Handles insert statements to view that are mapped to base tables' ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment