天天看点

OWA_UTIL.WHO_CALLED_ME解析

说明:

在撰写ETL调度工具时,在往日志表里面写调度日志时,需要写入当前执行的用户名称、执行作业的名称等信息,所以就想到了OWA_UTIL.WHO_CALLED_ME这个过程。

首先,来看一下官网解释:

 OWA_UTIL.WHO_CALLED_ME Procedure

This procedure returns information (in the form of output parameters) about the PL/SQL code unit that invoked it.

这个过程返回有关调用它的PL/SQL代码单元的信息(以输出参数的形式)。--为照顾英文能力差的朋友

语法:
OWA_UTIL.WHO_CALLED_ME解析
参数解释:
Parameter Description

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, or the name of the procedure or function if the calling program unit is a standalone procedure or function. If the calling program unit is part of an anonymous block, this is 

NULL

.--程序单元的名称。这是包的名称(如果调用程序单元包装在包中),或者是过程或函数的名称(如果调用程序单元是独立的过程或函数)。如果调用程序单元是匿名块的一部分,则该值为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 standalone procedures and functions.--发出调用的程序单元的类型。可能性有:包体、匿名块、过程和函数。过程和函数仅用于独立的过程和函数。这一点很重要,如果过程在包里面,返回的是包名。
 案例:

create or replace procedure child_proc(id number) as

owner_name    VARCHAR2 (100);

     caller_name   VARCHAR2 (100);

     line_number   NUMBER;

     caller_type   VARCHAR2 (100);

begin

     OWA_UTIL.WHO_CALLED_ME (owner_name,caller_name,line_number,caller_type);

     DBMS_OUTPUT.put_line (   '【id:】 ' || id

                        || '     【##caller_type:】 ' || caller_type

                           || '      【##owner_name:】 '  || owner_name

                           || '      【##caller_name:】 ' ||caller_name

                           || '      【##line_number:】 ' ||line_number

                          );

end;

/

create or replace procedure parent_proc as

v_child_proc VARCHAR2(100) := 'begin child_proc (1); end;';

begin

execute immediate v_child_proc;

child_proc (2);

end;

/

 下面进行测试:
OWA_UTIL.WHO_CALLED_ME解析

--记得执行一下输出,要不然后面不显示的。

OWA_UTIL.WHO_CALLED_ME解析

至此完毕,供参考。