获取 Oracle PL/SQL 中调用过程或函数的名称
有谁知道 PL/SQL 过程(在本例中是错误记录过程)是否可以获取调用它的函数/过程的名称?
显然,我可以将名称作为参数传递,但最好进行系统调用或其他方式来获取信息 - 如果不是从过程/函数调用它,它可能只返回 null 或其他内容。
如果没有方法,那也没关系 - 只是好奇是否可能(搜索不会产生任何结果)。
Does anyone know whether it's possible for a PL/SQL procedure (an error-logging one in this case) to get the name of the function/procedure which called it?
Obviously I could pass the name in as a parameter, but it'd be nice to make a system call or something to get the info - it could just return null or something if it wasn't called from a procedure/function.
If there's no method for this that's fine - just curious if it's possible (searches yield nothing).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个名为
OWA_UTIL
的包(旧版本的数据库中默认不安装该包)。它有一个方法WHO_CALLED_ME()
,它返回 OWNER、OBJECT_NAME、LINE_NO 和 CALLER_TYPE。请注意,如果调用者是打包过程,它将返回 PACKAGE 名称而不是过程名称。在这种情况下,无法获取过程名称;这是因为过程名称可以重载,所以它不一定很有用。了解更多信息。
从 10gR2 开始,还有
$$PLSQL_UNIT
特殊函数;这也将返回对象名称(即包而不是打包过程)。There is a package called
OWA_UTIL
(which is not installed by default in older versions of the database). This has a methodWHO_CALLED_ME()
which returns the OWNER, OBJECT_NAME, LINE_NO and CALLER_TYPE. Note that if the caller is a packaged procedure it will return the PACKAGE name not the procedure name. In this case there is no way of getting the procedure name; this is because the procedure name can be overloaded, so it's not necessarily very useful.Find out more.
Since 10gR2 there is also the
$$PLSQL_UNIT
special function; this will also return the OBJECT NAME (i.e. package not packaged procedure).我找到了这个论坛:http://www.orafaq.com/forum/t/60583/0/。这可能就是您正在寻找的。
基本上,您可以使用 Oracle 提供的
dbms_utility.format_call_stack
:I found this forum: http://www.orafaq.com/forum/t/60583/0/. It may be what you are looking.
Basically, you can use the Oracle supplied
dbms_utility.format_call_stack
:基本上,您需要做的就是定义变量并将它们传递到对实用程序方法的调用中,以用值填充它们:
Basically, all you need to do is to define vars and pass them in a call to a utility method to fill them up with values: