tags:

views:

1214

answers:

2

Can PL/SQL procedure in Oracle know it's own name?

Let me explain:

CREATE OR REPLACE procedure some_procedure is
    v_procedure_name varchar2(32);
begin
    v_procedure_name := %%something%%;
end;

After %%something%% executes, variable v_procedure_name should contain 'SOME_PROCEDURE'. It is also OK if it contains object_id of that procedure, so I can look up name in all_objects.

+5  A: 

Try:

v_procedure_name := $$PLSQL_UNIT;

There's also $$PLSQL_LINE if you want to know which line number you are on.

cagcowboy
Only returns the procedure name for stand alone procedures and functions, if called from a packaged procedure it returns the package name.
pablo
Indeed. Slightly irritating.
cagcowboy
+2  A: 

If you are pre-10g, you can 'dig' (parse) it out of dbms_utility.format_call_stack Procedures/functions in packages can be overloaded (and nested), so the package name/line number is normally better than the name.

Gary