oracle 找出 PL/SQL 过程的名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/286549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find out name of PL/SQL procedure
提问by icuric
Can PL/SQL procedure in Oracle know it's own name?
Oracle 中的 PL/SQL 过程可以知道它自己的名字吗?
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
.
后%%something%%
执行,变量v_procedure_name
应该包含“SOME_PROCEDURE”。如果它包含object_id
该过程也可以,因此我可以在all_objects
.
回答by cagcowboy
Try:
尝试:
v_procedure_name := $$PLSQL_UNIT;
There's also $$PLSQL_LINE if you want to know which line number you are on.
如果您想知道您所在的行号,还有 $$PLSQL_LINE 。
回答by Gary Myers
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.
如果您是 10g 之前的版本,则可以从 dbms_utility.format_call_stack 中“挖掘”(解析)它 包中的过程/函数可以重载(和嵌套),因此包名称/行号通常比名称更好。
回答by T. L. Jones
In 10g and 11g I use the "owa_util.get_procedure" function. I normally use this in packages as it will also return the name of an internal procedure or function as part of the package name, i.e. (package_name).(procedure name). I use this to provide a generic EXCEPTION
template for identifying where an exception occured.
在 10g 和 11g 中,我使用“owa_util.get_procedure”函数。我通常在包中使用它,因为它还会返回内部过程或函数的名称作为包名称的一部分,即 (package_name).(procedure name)。我使用它来提供一个通用EXCEPTION
模板来识别发生异常的位置。
CREATE OR REPLACE procedure some_procedure is
v_procedure_name varchar2(32);
begin
v_procedure_name := owa_util.get_procedure;
end;
CREATE OR REPLACE PACKAGE some_package
AS
FUNCTION v_function_name
RETURN DATE;
END;
/
CREATE OR REPLACE PACKAGE BODY some_package
AS
FUNCTION v_function_name
RETURN DATE
IS
BEGIN
RETURN SYSDATE;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR IN '||owa_util.get_procedure);
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
END;
/
回答by Howard Shulman
Here's a neat function that takes advantage of REGEXP_SUBSTR. I've tested it in a package (and it even works if another procedure in the package calls it):
这是一个利用 REGEXP_SUBSTR 的简洁函数。我已经在一个包中对其进行了测试(如果包中的另一个过程调用它,它甚至可以工作):
FUNCTION SET_PROC RETURN VARCHAR2 IS
BEGIN
RETURN NVL(REGEXP_SUBSTR(DBMS_UTILITY.FORMAT_CALL_STACK,
'procedure.+\.(.+)\s', 1,1,'i',1), 'UNDEFINED');
END SET_PROC;