Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Daniel.

Asked: July 04, 2019 - 7:18 am UTC

Last updated: July 08, 2019 - 3:03 am UTC

Version: 12c

Viewed 1000+ times

You Asked

Hi,

i have a task to prepare current functions inside package to catch exceptions on a way: "to get as many informations as possible about where exception occured".

My question is can i get the name of function/procedure in which exception happened without needing to change code inside them (many of those procedures are on different servers, schemas or they are not owned by my team) ?

I saw few examples but i didn't got results i realy wanted, using them.

I can't use debbug because i need those information from production environment.

Thanks form any tip.

If you need more examples or info i am here.

Kind regards

and Connor said...

Rating

  (1 rating)

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

Comments

Using UTL_CALL_STACK

Daniel Libric, July 05, 2019 - 10:26 am UTC

Thanks.
I tried it and it gives me some directions but it skips error from DBLINK calls.

Below is my example :

CREATE OR REPLACE PACKAGE_BODY ORGANIZATION_PACKAGE

FUNCTION get_organization_data(pin_parm)
  RETURN organization_tbl PIPELINED
IS
  key_data loan%rowtype;
  v_out_data organization_rec;
BEGIN

   SELECT * INTO key_data FROM LOANTBL WHERE key = pin_parm;
   
   SELECT NAME INTO v_out_data.NAME FROM SCHEMA1.ORGTBL WHERE ORG = key_data.org; -- I get data from another schema
   
   v_out_data.ADDRESS := address_pkg.address_data@<SERVER>@<SCHEMA>(key_data.org); -- I get data through DBLINK
   
   PIPE ROW(v_out_data);
   
END get_organization_data; 

END ORGANIZATION_PACKAGE;
-----------------------------------------------
FUNCTION test_func_main(pin_parm IN VARCHAR2)
 RETURN boolean
IS
  v_name varchar2(100);
  v_address varchar2(100);
BEGIN
  dbms_output.put_line('--- TESTING MAIN FUNCTION --- (' || pin_parm || ')');
  
  dbms_output.put_line('--------------------------------------------------------');
  dbms_output.put_line('--- GET DATA ABOUT ORGANIZATION ---');
 
  SELECT NAME, ADDRESS
    INTO v_name, v_address
    FROM TABLE (ORGANIZATION_PACKAGE.get_organization_data(pin_parm));
 
  RETURN(TRUE);

EXCEPTION
  WHEN NO_DATA_FOUND THEN
    dbms_output.put_line('NO DATA FOR ^^^^^^^^^^');
    RETURN(TRUE);
  WHEN OTHERS THEN
    dbms_output.put_line('ERROR-> ' || SQLERRM);
    RETURN(FALSE);

END test_func_main;

Connor McDonald
July 08, 2019 - 3:03 am UTC

Yes, you would need to catch the error in the *remote* package and interrogate UTL_CALL_STACK there

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