RETURNING clause when inserting into a view
I have got two tables named H_HELP and AUDIT_INFO. I have created a trigger on H_HELP to populate the primary key (helpid) with a sequence, a view V_HELP on the natural join of the two tables, and a trigger INSTEAD OF INSERT ON V_HELP, which does inserts in H_HELP and AUDIT_INFO together. This works fine (see source at the end of the post if you need it).
But it gets wrong when I want to do an insert to V_HELP using the returning clause to get the automatically generated helpid :
SQL> INSERT INTO V_HELP (label,usr_resp,grp_resp,usr_crea)
2 VALUES('Something','XXXX','AAAA','YYYY') RETURNING helpid INTO v_helpid;
INSERT INTO V_HELP (label,usr_resp,grp_resp,usr_crea)
*
ERREUR Ã la ligne 1 :
ORA-22816: fonction non prise en charge avec la clause RETURNING
It looks like the returning clause is not supported when inserting into a view, what the description of ORA-22816 doesn't make clear. And I don't really see any workaround which will safely return the automatically generated helpid (other than throwing away my view and using procedures instead of triggers). Do you see any solution using the view ?
-------------
As addendum, here is the code for the view and the triggers
CREATE OR REPLACE FORCE VIEW HELP_DATA.V_HELP
(HELPID, LABEL, USR_RESP, GRP_RESP, DURATION,
TIME_UNIT, START_DATE, USR_CREA, DAT_CREA, USR_MOD,
DAT_MOD)
AS
SELECT helpid,label, usr_resp,grp_resp,duration,time_unit,start_date,
usr_crea,dat_crea,usr_mod,dat_mod
FROM h_help NATURAL JOIN audit_info;
CREATE OR REPLACE TRIGGER HELP_DATA.T_INSERT_V_HELP
INSTEAD OF INSERT
ON HELP_DATA.V_HELP
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_auditid NUMBER;
BEGIN
INSERT INTO AUDIT_INFO (usr_crea) VALUES (:NEW.usr_crea) RETURNING auditid INTO v_auditid;
INSERT INTO H_HELP (label,usr_resp,grp_resp,duration,time_unit,start_date,auditid)
VALUES(:NEW.label,:NEW.usr_resp,:NEW.grp_resp,:NEW.duration,:NEW.time_unit,:NEW.start_date,v_auditid);
END ;
/
CREATE OR REPLACE TRIGGER HELP_DATA.T_INSERT_H_HELP
BEFORE INSERT
ON HELP_DATA.H_HELP
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_helpid NUMBER;
BEGIN
SELECT H_HELP_HELPID_SEQ.NEXTVAL INTO v_helpid FROM dual;
:NEW.helpid := v_helpid;
END ;
/