can you write commit in triggers?

Answer Posted / guru

----------- without AUTONOMOUS_TRANSACTION

CREATE or REPLACE TRIGGER parts_trig
BEFORE INSERT ON parts
FOR EACH ROW
BEGIN
INSERT INTO parts_log VALUES(:new.pnum, :new.pname);
END;
/
INSERT INTO parts VALUES (1040, 'Head Gasket');
COMMIT;
INSERT INTO parts VALUES (2075, 'Oil Pan');
ROLLBACK;

SELECT * FROM parts ORDER BY pnum;
SELECT * FROM parts_log ORDER BY pnum;

----------- using AUTONOMOUS_TRANSACTION

CREATE or REPLACE TRIGGER parts_trig
BEFORE INSERT ON parts FOR EACH ROW
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO parts_log VALUES(:new.pnum, :new.pname);
COMMIT; -- only for AUTONOMOUS_TRANSACTION
END;
/
INSERT INTO parts VALUES (1040, 'Head Gasket');
COMMIT;
INSERT INTO parts VALUES (2075, 'Oil Pan');
ROLLBACK;
/


Please Check This


Thanks

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can u please explain me the Discussion on Except ,using cast like type cast. Question in the context of difference between two tables

1813


Explain the use of file option in exp command.

889


How to filter out duplications in the returning rows using oracle?

855


What is the effect of setting the value "all_rows" for optimizer_goal parameter of the alter session command? What are the factors that affect optimizer in choosing an optimization approach?

767


Write a trigger example in oracle?

810


HI, Please let me know the syllabus for Oracle OCA and OCP Certification

2230


why should i declare foreign key constraint as self relation instead of binary relation in tables ?

1822


What is oracle thin client?

790


How to create a new table in your schema?

826


1) Does oracle have any table which contain all the exceptions and it's code internally?

1520


Database crashes. Corruption is found scattered among the file system neither of your doing nor of Oracles. What database recovery options are available? Database is in archive log mode.

1767


Explain the truncate in oracle?

738


How to assign data of the deleted row to variables?

832


Give the advantages and disadvantages of clusters.

803


How to invoke the original export import utilities?

714