Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Can you load data into multiple tables at once? : aql loader

1021


Can we alter stored procedure?

943


what is a table called, if it has neither cluster nor non-cluster index? What is it used for? : Sql dba

931


What is java sql drivermanager?

1020


What is indexing in sql and its types?

1004


Is sql developer case sensitive?

944


Explain exception handling in pl/sql?

988


How do sql triggers work?

987


What are the different sql languages?

985


What is clustered index sql?

931


Can we use rowid as primary key?

942


Define implicit and explicit cursors.

1074


What is the use of primary key?

952


What is the use of procedures?

924


What is percent sign in sql?

1213