can you write commit in triggers?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / selvam.p
No, In normal condition, commit or rollback inside the
trigger is not possible.
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / sudhir
by default Trigger doesnt allow a commit;
however we can create a stored procedure which will only do
commit.
create or replace procedure to_commit_trigger
begin
commit();
end to_commit_trigger
now execute this stored procedure to_commit_trigger inside a
trigger to perform a commit. However it will cause serious
performance issues.
| Is This Answer Correct ? | 0 Yes | 3 No |
What do you mean by merge in oracle and how can we merge two tables?
What are the varoius components of physical database structure of oracle database?
What happens to the current transaction if a ddl statement is executed?
How to check database size in Oracle?
State any two functions of oracle?
How can I combine multiple rows into a comma-delimited list in oracle?
In what script is snap$ created? In what script is the scott/tiger schema created?
Explain index?
can you call insert/update/delete in select statements. If yes how? If no what is the other way?
How many types of tables are there in oracle?
What is the effect of setting the value 'FIRST_ROWS' for OPTIMIZER_GOAL parameter of the ALTER SESSION command ?
What is the relation of a user account and a schema in oracle?