Home » SQL & PL/SQL » SQL & PL/SQL » Get name of function
Get name of function [message #305625] Tue, 11 March 2008 07:19 Go to next message
KieranJ
Messages: 3
Registered: March 2008
Junior Member
Is there a way of getting the name of the function that is currently executing from inside it?

eg.


create or replace procedure test is 
  func_name varchar2(50);
begin
  func_name := 'test'; -- Automate this
  dbms_output.put_line(func_name);
end;
Re: Get name of function [message #305629 is a reply to message #305625] Tue, 11 March 2008 07:31 Go to previous messageGo to next message
dhananjay
Messages: 635
Registered: March 2002
Location: Mumbai
Senior Member
don't know if there any such thing which will tell you the current executing function.But what is the purpose you are trying to achive here?

regards
Re: Get name of function [message #305632 is a reply to message #305625] Tue, 11 March 2008 07:36 Go to previous messageGo to next message
S.Rajaram
Messages: 1027
Registered: October 2006
Location: United Kingdom
Senior Member
SQL> create or replace procedure test_proc
  2  is
  3  begin
  4  dbms_output.put_line('My Name is : ' || $$PLSQL_UNIT);
  5  end;
  6  /

Procedure created.

SQL> exec test_proc;
My Name is : TEST_PROC

PL/SQL procedure successfully completed.

SQL> declare
  2  begin
  3  dbms_output.put_line('My name is : ' || $$PLSQL_UNIT);
  4  end;
  5  /
My name is :

PL/SQL procedure successfully completed.


Remember above code will only for stored proc or functions or packages. It will return null for an anonymous block and it will return the name of the package body and not the procedure / function defined in the package.

HTH

Regards

Raj

Re: Get name of function [message #305635 is a reply to message #305632] Tue, 11 March 2008 07:44 Go to previous messageGo to next message
KieranJ
Messages: 3
Registered: March 2008
Junior Member
Thanks, that's exactly what I needed.

K
Re: Get name of function [message #306008 is a reply to message #305632] Wed, 12 March 2008 09:53 Go to previous messageGo to next message
KieranJ
Messages: 3
Registered: March 2008
Junior Member
Out of curiosity, is there any way to return the procedure/function name if it's being called from within a package?

[Updated on: Wed, 12 March 2008 09:53]

Report message to a moderator

Re: Get name of function [message #306027 is a reply to message #305625] Wed, 12 March 2008 10:43 Go to previous messageGo to next message
BlackSwan
Messages: 25033
Registered: January 2009
Location: SoCal
Senior Member
does this help?
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1529405950004
Re: Get name of function [message #306448 is a reply to message #305625] Fri, 14 March 2008 04:51 Go to previous messageGo to next message
hari.choprala
Messages: 65
Registered: November 2006
Location: Mumbai
Member

Hi Raj,

Your Solution is not working for me. Iam getting PLS-00103 error.

My oracle version is

SQL> select banner from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
CORE	9.2.0.1.0	Production

TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
NLSRTL Version 9.2.0.1.0 - Production



For which version it will work?

Thanks
Hari Krishna
Re: Get name of function [message #306449 is a reply to message #306448] Fri, 14 March 2008 05:11 Go to previous message
S.Rajaram
Messages: 1027
Registered: October 2006
Location: United Kingdom
Senior Member
This features is introduced in 10gR2 and it is simple. Prior to that version refer the link posted by @anacedent. It has examples how to extract this information.

Regards

Raj
Previous Topic: PLS-00231 depending on function's access modifier
Next Topic: UTL_MAIL PROBLEM
Goto Forum:
  


Current Time: Fri Dec 02 22:55:35 CST 2016

Total time taken to generate the page: 0.04758 seconds