题记:人有时候就好像这存储过程,只有通过和别人交流才能清楚才能知道自己到底是个什么东西!那怕是最最基本的东西你自己都不一定知道。傻B了吧……
----------------调皮的分割线----------------
在Oracle中,存储过程和函数等对象,可通过调用OWA_UTIL包中的who_called_me过程来获得自身的名称和类型。
以下是Oracle联机文档对该过程的说明,该过程将返回调用者的一些信息。
Syntax: | owa_util.who_called_me( owner out varchar2 name out varchar2 lineno out number caller_t out varchar2); |
Parameters: | owner - the owner of the program unit. name - the name of the program unit. This is the name of the package, if the calling program unit is wrapped in a package, and the name of the procedure or function if the calling program unit is a stand-alone procedure or function. If the calling program unit is part of an anonymous block, this is NULL. lineno - the line number within the program unit where the call was made. caller_t - the type of program unit that made the call. The possibilities are: package body, anonymous block, procedure, and function. Procedure and function are only for stand-alone procedures and functions. |
Generates | Not applicable. |
在网上摘了一个应用的例子:
CREATE OR REPLACE FUNCTION fn_getname
RETURN VARCHAR2
IS
l_owner VARCHAR2 (30);
l_name VARCHAR2 (30);
l_lineno NUMBER;
l_type VARCHAR2 (30);
BEGIN
OWA_UTIL.who_called_me (l_owner, l_name, l_lineno, l_type);
RETURN l_owner || '.' || l_name||':'||to_char(l_lineno)||','||l_type;
END;
/
CREATE OR REPLACE PROCEDURE demo
AS
BEGIN
DBMS_OUTPUT.put_line (fn_getname);
END;
/
call demo();
通过该例可以了解该过程的应用。看起来,好像函数对象只能通过who_called_me获得自己调用者的信息,调用者通过调用函数来获取自己的信息……真纠结。