December 11, 2008

When recompiling package invalidate other package

Filed under: Works

Gosh…no way…after recompiling a package, it turned out to be invalidated other package. When I recompiling again the other package, it also invalidated another package..oh no!!! I would say this as "lingkaran setan" *jejeje

Well, there is a simple way to avoid this (acted like a pro, wacks!! huhu) .Rather than recompiling the entire package, just try to recompile only the package bodies, that is if the package spec is not invalid. Compiling the entire package can invalidate other objects; compiling just the body avoids this.

Yeah, another stupidity of me, arrgghh…But, at least I manage to get out from the "lingkaran setan" ^^

December 4, 2008

Autonomous Transaction

Filed under: Works

First, I dont know what autonomous means..hehehe, lack of vocabulary :p

I am quotting from online dictionary, it is said that Autonomous means not controlled by others or by outside forces; independent. Combine it with transaction, it becomes an independent transaction, not controlled by other transactions.

Now, the meaning of autonomous transaction in PL/SQL pretty clear:

"Pragma Autonomous Transaction is which is executed in the execution of another transaction known as parent transaction which is independent of it or the whole transaction splits in to two parts known as parent& child will be independent of both but have the same relationship."

When you are writing a PL/SQL block (procedure or trigger) with insert or update statement followed by commit, try to include PRAGMA AUTONOMOUS TRANSACTION in the declare part. It will perform that commit as an independent transaction despite of other transaction is being rolled back or commited.

In the above example, we created a procedure INSERT_INTO_T. In this procedure we used the new pragma AUTONOMOUS_TRANSACTION. That directive tells the database that this procedure, when executed, is to be executed as a new subtransaction – independent from its parent transaction. This procedure simply inserts a record with the value of ‘1’ into the table T and commits. We then proceed to create an anonymous PL/SQL block in which we insert the value of ‘-1’ into T, invoke the stored procedure INSERT_INTO_T and rollback. Prior to autonomous transactions, the commit in the subroutine INSERT_INTO_T would have committed not only the work it performed (the insert of ‘1’) but any outstanding work the session had performed and not yet committed (the insert of ‘-1’ in the anonymous block). The rollback would have rolled back no work since the commit in the procedure would have committed both inserts. We see this is not the case with autonomous transactions. The work performed in the procedure marked with AUTONOMOUS_TRANSACTION was committed however the work performed outside the autonomous transaction was rolled back.

What is it used for? It is for audit trail purpose. And what is audit trail used for??? Hm, still a mystery for me ^^ next time laaahhh

 

 

 






















Get free blog up and running in minutes with Blogsome
Theme designed by Helga Cleve