Can we use commit or rollback in trigger? If yes, then how. Please explain with a suitable example?

Answer Posted / santosh kumar

Yes ,You can Commit inside the trigger.

But for this you have to make this trigger transaction to be a Independent transaction from its parent transaction, You can do this by using Pragma. Pragma AUTONOMOUS_TRANSACTION allow you to build the Indepadent(child) Transaction,started by another. Shold be declare in DECLARE section of any subprogram.

Used to make Modular and Resuable Blocks. if you need the example then ask to me.

CREATE OR REPLACE TRIGGER TRIG_ARG
AFTER INSERT ON TAB1
DECLARE
PRAGMA AUTONOMOUNS_TRNASACTION
BEGIN
INSERT INTO LOG VALUES(SYSDATE,'INSERT ON TAB1');
COMMIT;
END;
/

OR

CREATE OR REPLACE TRIGGER t_trigger
AFTER INSERT ON t1 FOR EACH ROW

DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
i PLS_INTEGER;
BEGIN
SELECT COUNT(*)
INTO i
FROM t1;

INSERT INTO t2
VALUES
(i);
COMMIT;
END;
/

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is the difference between group by and order by in sql? : Sql dba

763


What is $$ in sql?

728


Can we create table in function?

730


How many triggers can be applied to a table?

779


What is an implicit commit?

761






Does pdo prevent sql injection?

695


Explain the significance of the & and && operators in pl sql.

748


How many types of functions are there in sql?

666


what is sql? : Sql dba

741


What are the different operators available in sql?

747


What is the purpose of the sql select top clause?

736


How is a process of pl/sql compiled?

775


What is an emotional trigger?

695


Which are sql * plus commands?

714


what is 'mysqlcheck'? : Sql dba

746