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

 What are the oracle DML commands possible through an update strategy?

579


What is a synonym? What are its various types?

622


How many types of synonyms in Oracle?

591


How to increment dates by 1 in oracle?

557


defination of bitmap index

1621






How to check the oracle tns settings?

571


What is set verify off in oracle?

573


what is partitioning? Types of partitioning. explain? what is the new kind of partitioning type introduced in 9i?

1845


Briefly explain what is literal? Give an example where it can be used?

540


how can db_files > maxdatafiles since db_files is for instance and the later is for database

2173


List out the components of logical database structure of oracle database.

581


What is a oracle database?

605


How do I find my oracle client driver version?

522


What are the components of logical database structure in oracle database?

575


How to define an oracle cursor variable?

563