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

Is there any way to find out when one specific table/view/M-view is used last time. i.e. when one specific object is used in any SELECT statement.

859


What is a dynamic performance view in oracle?

608


how to make an oracle object

1858


How to define an anonymous procedure with variables?

545


How to define a data source name (dsn) in odbc manager?

529






Using the relations and the rules set out in the notes under each relation, write table create statements for the relations EMPLOYEE, FIRE and DESPATCH. You should aim to provide each constraint with a formal name, for example table_column_pk.

1365


How can we create the complete backup of data in the oracle.

1685


Explain the use of parfile option in exp command.

526


Define oracle database

596


List the various oracle database objects?

599


What are the attributes that are found in a cursor?

650


Which is better Oracle or MS SQL? Why?

3978


How to end the current transaction in oracle?

560


what is port in oracle? how is it related to database application.

1438


What are ddl statements in oracle?

592