05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

276<br />

CHAPTER 8 ■ TRANSACTIONS<br />

■Note A pragma is simply a compiler directive, a method to instruct the compiler to perform some compilation<br />

option. Other pragmas are available. Refer to the PL/SQL programming manual <strong>and</strong> you will see a list<br />

of them in its index.<br />

And here’s the “normal” NONAUTONOMOUS_INSERT procedure:<br />

ops$tkyte@ORA10G> create or replace procedure NonAutonomous_Insert<br />

2 as<br />

3 begin<br />

4 insert into t values ( 'NonAutonomous Insert' );<br />

5 commit;<br />

6 end;<br />

7 /<br />

Procedure created.<br />

Now let’s observe the behavior of the nonautonomous transaction in an anonymous block<br />

of PL/SQL code:<br />

ops$tkyte@ORA10G> begin<br />

2 insert into t values ( 'Anonymous Block' );<br />

3 NonAutonomous_Insert;<br />

4 rollback;<br />

5 end;<br />

6 /<br />

PL/SQL procedure successfully completed.<br />

ops$tkyte@ORA10G> select * from t;<br />

MSG<br />

-------------------------<br />

Anonymous Block<br />

NonAutonomous Insert<br />

As you can see, the work performed by the anonymous block, its INSERT, was committed<br />

by the NONAUTONOMOUS_INSERT procedure. Both rows of data were committed, so the ROLLBACK<br />

comm<strong>and</strong> had nothing to roll back. Compare this to the behavior of the autonomous transaction<br />

procedure:<br />

ops$tkyte@ORA10G> delete from t;<br />

2 rows deleted.<br />

ops$tkyte@ORA10G> commit;<br />

Commit complete.<br />

ops$tkyte@ORA10G> begin<br />

2 insert into t values ( 'Anonymous Block' );

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!