Created
February 26, 2018 06:48
-
-
Save vithalsamp/da82c466d733e13727b20e4a067e9c1e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 PROCEDURE return_result() RETURNS | |
REFTABLE(tab1) LANGUAGE NZPLSQL AS | |
BEGIN_PROC | |
BEGIN | |
-- Insert into REF TABLE | |
EXECUTE IMMEDIATE 'INSERT INTO ' || REFTABLENAME ||' values (111, 100,''ABC'',200)'; | |
EXECUTE IMMEDIATE 'INSERT INTO ' || REFTABLENAME ||' values (112, 101,''AAA'',202)'; | |
EXECUTE IMMEDIATE 'INSERT INTO ' || REFTABLENAME ||' values (113, 102,''BBB'',201)'; | |
--Use query to insert data | |
EXECUTE IMMEDIATE 'INSERT INTO ' || REFTABLENAME ||' SELECT * FROM STUD_REC'; | |
-- Handle Exception anything | |
EXCEPTION WHEN OTHERS THEN | |
RAISE NOTICE 'Got an exception! Please check table and queries: %', SQLERRM; | |
RETURN REFTABLE; | |
END; | |
END_PROC; | |
--Execute the stored procedure and check output | |
TRAINING.ADMIN(ADMIN)=> call return_result(); | |
ID | DEPT | NAME | SUB_CODE | |
-----+------+------+---------- | |
112 | 101 | AAA | 202 | |
112 | 101 | AAA | 202 | |
116 | 100 | ZZZ | 207 | |
114 | 100 | CCC | 200 | |
113 | 102 | BBB | 201 | |
113 | 102 | BBB | 201 | |
117 | 104 | YYY | 200 | |
111 | 100 | ABC | 200 | |
111 | 100 | ABC | 200 | |
115 | 102 | DDD | 205 | |
(10 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment