Skip to Main Content
  • Questions
  • How to trace plsql executed by a package or a procedure

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Samuel.

Asked: April 07, 2017 - 1:27 am UTC

Last updated: April 08, 2017 - 5:06 am UTC

Version: Oracle 12c

Viewed 10K+ times! This question is

You Asked

Hi,

In an application that we use (which uses Oracle as the database to store data), when we update and save data, it internally calls a plsql package or a procedure to invoke an UPDATE statement.

We have traced the UPDATE statement using db level sql trace. But we want to trace the plsql package or procedure which fires the UPDATE statement during save.

I did some research and found that we could enable PLSQL trace using "ALTER SESSION SET plsql_debug=TRUE;" and then trace all calls.
But I realized that this method works only for a specific session where we initiate a session, enable plsql trace and then call the package or procedure.

So, is there a way to trace plsql code from the database, which is invoked by an application?
Please help!

Sam

and Connor said...

If you control over the code, your best bet is to instrument it.

http://asktom.oracle.com/Misc/instrumentation.html

But if you cannot, then you can still perhaps get some benefit from plsql trace

1) create a login trigger to call

dbms_trace.set_plsql_trace(dbms_trace.TRACE_ENABLED_CALLS+dbms_trace.TRACE_LIMIT);

2) only compile the procedure in question in debug mode

The use of "trace_limit" will mean you'll only get the last 8192 calls to stop things from going ballistic.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

What if we don't know the package that is getting called

Sam, April 07, 2017 - 6:19 am UTC

Hi Connor,

Thank you for your response.

We don't have control over the code, so I can go for option 2.

The problem we are facing is that we don't know which package / procedure is getting called during the Save operation.
So I won't be able to compile the package/procedure in debug code.

The ultimate objective is to find out the package name which is getting called during Save operation.

Thanks,
Sam
Connor McDonald
April 08, 2017 - 5:06 am UTC

If you can isolate a piece of SQL, then it is easy to find the source of the PL/SQL that issued it

https://connormcdonald.wordpress.com/2016/01/20/problematic-sql-plsql-is-your-friend/

Is it possible to trace the package getting called during save operation

A reader, April 07, 2017 - 8:23 am UTC

We can only go for plsql trace since we don't know the code getting fired during save operation.

So, since we can't compile the package in debug mode, what are my options to trace the package/procedure getting called?

To "A reader" : yes you can...

J. Laurindo Chiappa, April 07, 2017 - 2:23 pm UTC

Well, for starting nothing stops you from compile in debug mode ANY PL/SQL, if you have access to the owner OR if you have admin rights/ANY privs in the database - just for security obviously you would do it in the HOMOLOGATION environment, using a COPY of the application, not directly in PROD : basic rule in Development...
If you donĀ“t know the name / the list of all procedures being called by this "SAVE" routine (not a faintest idea about what it can be, but matters not), an option could be star SQL TRACE (event 10046) in the session execution the "SAVE" routine - with this, the list of executed procedures will appear in the trace file in the form :

...
=====================
PARSING IN CURSOR #xxx len=51 dep=0 uid=180 oct=47 lid=180 tim=11746424051712 hv=2083693016 ad='27ecb338'
BEGIN nameoftheproceduret(arguments); END;
END OF STMT
PARSE #18:c=0,e=3072,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=11746424051712
=====================
...

With this, you get the names of them and could compile all of them in DEBUG mode, and later debug them with SQL Developer, TOAD or whatever tool you want to use....

Best regards,

J. Laurindo Chiappa

P.S. : of course, the trace 10046 per se will give to you performance measures for ALL the SQL executed in the session being traced - if this is useful to you, use this information, too...

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library