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
What is mutating sql table?
How many types of literals are available in pl sql?
What is sql profiling in oracle?
What does partition by mean in sql?
What type of join is sql join?
Can a foreign key have a different name?
Explain the methods used to protect source code of pl/sql.
what is the difference between clustered and non clustered index in sql? : Sql dba
Is full outer join same as cross join?
What are the sql versions?
Is primary key always clustered index?
what is bdb (berkeleydb)? : Sql dba
What is percent sign in sql?
How to call shell script from pl sql procedure?
Which is better varchar or nvarchar?