Oracle PL/SQL: how to get the stack trace, package name and procedure name(Oracle PL/SQL:如何获取堆栈跟踪、包名称和过程名称)
问题描述
有时异常返回类似:ORA-06502:PL/SQL:数字或值错误:字符串缓冲区太小".
Sometimes the exception returns something like: "ORA-06502: PL/SQL: numeric or value error: character string buffer too small".
它不是那么易读,因为它既不报告表、列和它试图写入的值.
It's not so readable since it doesn't report neither the table, the column and the value it tried to write.
在异常发生或被捕获时获取当前过程名称会很有用.
it would be useful to get the current procedure name at the moment the Exception happened or is catched.
我如何获得它?
推荐答案
您可能想要 DBMS_UTILITY.FORMAT_ERROR_BACKTRACE 函数
You probably want DBMS_UTILITY.FORMAT_ERROR_BACKTRACE function
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure p1
2 is
3 begin
4 raise_application_error( -20001, 'Error 1', true );
5* end;
SQL> /
Procedure created.
SQL> create or replace procedure p2
2 as
3 begin
4 null;
5 p1;
6 end;
7 /
Procedure created.
SQL> begin
2 p2;
3 exception
4 when others then
5 dbms_output.put_line( dbms_utility.format_error_backtrace );
6 end;
7 /
ORA-06512: at "SCOTT.P1", line 4
ORA-06512: at "SCOTT.P2", line 5
ORA-06512: at
line 2
PL/SQL procedure successfully completed.
这篇关于Oracle PL/SQL:如何获取堆栈跟踪、包名称和过程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Oracle PL/SQL:如何获取堆栈跟踪、包名称和过程名称
基础教程推荐
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
