Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Autonomous Transactions usage in PL/SQL anonymous block coding

576644May 9 2007 — edited May 9 2007
Hi,

I am trying to incorporate Autonomous Transaction for our work. I am using the tables provided below,


CREATE TABLE T1
(
F1 INTEGER,
F2 INTEGER
)
/


CREATE TABLE T2
(
F1 INTEGER,
F2 INTEGER
)
/

insert into t1(f1, f2)
values(20, 0)
/

insert into t2(f1, f2)
values(10, 0)
/

Now, when I use the code snippet given below, it is working as expected.

create or replace procedure p1 as
PRAGMA AUTONOMOUS_TRANSACTION;
begin

update t2
set f2 = 25
where f1 = 10;

commit;
end;

declare
PRAGMA AUTONOMOUS_TRANSACTION;
a integer;
begin

update t1
set f2 = 15
where f1 = 20;

p1();

rollback;
end;

Here, updation in t2 table is commited and t1 is rolled back, it is working as
expected. I would like to achieve the same functionality through PL/SQL
anonymous block coding, to do this, I use the following code snippet,

declare
PRAGMA AUTONOMOUS_TRANSACTION;
a integer;
begin

update t1
set f2 = 15
where f1 = 20;

begin

update t2
set f2 = 35
where f1 = 10;

commit;
end;


rollback;
end;

Here, data in both the tables are commited, how do I change it to work as I
mentioned above like committing t2 alone, please help, thank you.

Regards,
Deva
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2007
Added on May 9 2007
7 comments
1,946 views