Sunday, May 1, 2011

Is it possible to know from which package a procedure has been called ?

Suppose that I have 2 packages : A and B.

In package A, I call a procedure in package B.

In procedure of packcage B, is it possible to know that procedure has been called from package A ?


Thank you very much for these informations. It was very instructive.

I appreciate.

From stackoverflow
  • You may be able to parse the text returned by the DBMS_UTILITY.FORMAT_CALL_STACK() function.

    Edit: I tried creating some test packages. I have a procedure in the XX_TESTA package calling another in the XX_TESTB package. The procedure in XX_TESTB simply prints the text returned by DBMS_UTILITY.FORMAT_CALL_STACK() to output. This is the resulting text:

    ----- PL/SQL Call Stack -----
      object      line  object
      handle    number  name
    416fe0e68         5  package body APPS.XX_TESTB
    415182f10         5  package body APPS.XX_TESTA
    416e9b448         3  anonymous block
    
    cagcowboy : Probably a better suggestion than mine. I find $$PLSQL_UNIT really useful but I don't think it's that well known because it's relatively new.
  • You could pass the name through as a parameter?

    Using....

    $$PLSQL_UNIT
    

    From: http://awads.net/wp/2006/08/03/heres-a-quick-way-to-get-the-line-number-in-plsql

    EDDIE@XE> CREATE OR REPLACE PACKAGE my_pkg
      2  IS
      3     PROCEDURE my_proc;
      4  END;
      5  /
    
    Package created.
    
    EDDIE@XE> CREATE OR REPLACE PACKAGE BODY my_pkg
      2  IS
      3     PROCEDURE my_proc
      4     IS
      5     BEGIN
      6        DBMS_OUTPUT.put_line ('Line number: ' || $$plsql_line);
      7        DBMS_OUTPUT.put_line (   'Unit: '
      8                              || $$plsql_unit
      9                             );
     10     END;
     11  END;
     12  /
    
    Package body created.
    
    EDDIE@XE> exec my_pkg.my_proc;
    Line number: 6
    Unit: MY_PKG
    
    Luc M : Thanks for the link. There's many interesting articles! Added into my rss reader :-)
  • You can use procedure called who_called_me from the Oracle supplied package OWA_UTIL

    http://download.oracle.com/docs/cd/B25221_04/web.1013/b25598/psutil.htm#i1006497

0 comments:

Post a Comment