PL/SQL精明的调用栈分析
PL/SQL精明的调用栈分析
原文:http://www.oracle.com/technetwork/issue-archive/2014/14-jan/o14plsql-2045346.html
The three DBMS_UTILITY functions
(DBMS_UTILITY.FORMAT_CALL_STACK, DBMS_UTILITY.FORMAT_ERROR_STACK, and DBMS_UTILITY.FORMAT_ERROR_ BACKTRACE) have been crucial aids in diagnosing and resolving problems in PL/SQL code. The UTL_CALL_STACK package recognizes the importance of this data and takes a big step forward in giving PL/SQL developers access to more in-depth and useful information
12C曾经的3个工具函数(DBMS_UTILITY.FORMAT_CALL_STACK,DBMS_UTILITY.FORMAT_ERROR_STACK,DBMS_UTILITY.FORMAT_ERROR_ BACKTRACE)
已经给PL/SQL程序分析和问题解决提供了关键的帮助。
12C開始引入的UTL_CALL_STACK包意识到改类数据的重要性并进一步增强以使PL/SQL开发人员能够获得很多其它深层次的实用的信息。
–调用栈 Call Stacks :DBMS_UTILITY.FORMAT_CALL_STACK
回答了 “How did I get here?
” 。我是怎么一步一步到达这里的?比如:
SQL> CREATE OR REPLACE PROCEDURE proc1
2 IS
3 BEGIN
4 DBMS_OUTPUT.put_line (DBMS_UTILITY.format_call_stack);
5 END;
6 /
SQL> CREATE OR REPLACE PACKAGE pkg1
2 IS
3 PROCEDURE proc2;
4 END pkg1;
5 /
SQL> CREATE OR REPLACE PACKAGE BODY pkg1
2 IS
3 PROCEDURE proc2
4 IS
5 BEGIN
6 proc1;
7 END;
8 END pkg1;
9 /
SQL> CREATE OR REPLACE PROCEDURE proc3
2 IS
3 BEGIN
4 FOR indx IN 1 .. 1000
5 LOOP
6 NULL;
7 END LOOP;
8
9 pkg1.proc2;
10 END;
11 /
SQL> BEGIN
2 proc3;
3 END;
4 /
——————— PL/SQL Call Stack ———————
object handle line number object name
000007FF7EA83240 4 procedure HR.PROC1
000007FF7E9CC3B0 6 package body HR.PKG1
000007FF7EA0A3B0 9 procedure HR.PROC3
000007FF7EA07C00 2 anonymous block
–弊端:
If you call a subprogram in a package, the formatted call stack will show only the package name, not the subprogram name and certainly not the names of nested subprograms defined within that packaged subprogram.
假设我们调用包中的子程序,那么此函数只能显示报名。压根不会显示子程序的名称更别提嵌套子程序的名称了。
If you simply want the name of the most recently executed subprogram, you will have to parse the string. This is not hard to do, but it’s more code that you have to write and maintain.
假设我们只想看下近期运行的子程序名称,还得去解析冗长的字符串。尽管这并非难事,但无疑加重了开发人员的负担。
The object handle value is, for all practical purposes, “noise.” PL/SQL developers—outside of Oracle, at least—never use it.
object handle值是个鸡肋,无实际用途。
–错误栈 Error Stacks :DBMS_UTILITY.FORMAT_ERROR_STACK Similar to SQLERRM
The DBMS_UTILITY.FORMAT_ERROR_STACK function differs from SQLERRM in two ways:
It can return an error message as long as 1,899 characters, thereby avoiding (or at least making extremely unlikely) truncation issues when the error stack gets long. (SQLERRM truncates at only 510 characters.)
You cannot pass an error code number to this function, and it cannot be used to return the message for an error code.
–错误回溯 Error Backtraces :DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
returns a formatted string that displays a stack of programs and line numbers tracing back to the line on which the error was originally raised.
12c: UTL_CALL_STACK package
Name Description
BACKTRACE_DEPTH Returns the number of backtrace items in the backtrace
BACKTRACE_LINE Returns the line number of the unit at the specified backtrace depth
BACKTRACE_UNIT Returns the name of the unit at the specified backtrace depth
CONCATENATE_SUBPROGRAM Returns a concatenated form of a unit-qualified name
DYNAMIC_DEPTH Returns the number of subprograms in the call stack, including SQL, Java, and other non-PL/SQL contexts invoked along the way—for example, if A calls B calls C calls B, this stack, written as a line with dynamic depths underneath it, will look like this:
A B C B
4 3 2 1
ERROR_DEPTH Returns the number of errors in the call stack
ERROR_MSG Returns the error message of the error at the specified error depth
ERROR_NUMBER Returns the error number of the error at the specified error depth
LEXICAL_DEPTH Returns the lexical nesting level of the subprogram at the specified dynamic depth
OWNER Returns the owner name of the unit of the subprogram at the specified dynamic depth
UNIT_LINE Returns the line number of the unit of the subprogram at the specified dynamic depth
SUBPROGRAM Returns the unit-qualified name of the subprogram at the specified dynamic depth
SQL> CREATE OR REPLACE PROCEDURE format_call_stack_12c
2 IS
3 BEGIN
4 DBMS_OUTPUT.put_line (
5 'LexDepth Depth LineNo Name');
6 DBMS_OUTPUT.put_line (
7 '-------- ----- ------ ----');
8
9 FOR the_depth IN REVERSE 1 ..
10 utl_call_stack.dynamic_depth ()
11 LOOP
12 DBMS_OUTPUT.put_line (
13 RPAD (
14 utl_call_stack.lexical_depth (
15 the_depth),
16 9)
17 || RPAD (the_depth, 5)
18 || RPAD (
19 TO_CHAR (
20 utl_call_stack.unit_line (
21 the_depth),
22 '99'),
23 8)
24 || utl_call_stack.concatenate_subprogram (
25 utl_call_stack.subprogram (
26 the_depth)));
27 END LOOP;
28 END;
29 /
SQL> CREATE OR REPLACE PACKAGE pkg
2 IS
3 PROCEDURE do_stuff;
4 END;
5 /
SQL> CREATE OR REPLACE PACKAGE BODY pkg
2 IS
3 PROCEDURE do_stuff
4 IS
5 PROCEDURE np1
6 IS
7 PROCEDURE np2
8 IS
9 PROCEDURE np3
10 IS
11 BEGIN
12 format_call_stack_12c;
13 END;
14 BEGIN
15 np3;
16 END;
17 BEGIN
18 np2;
19 END;
20 BEGIN
21 np1;
22 END;
23 END;
24 /
SQL> BEGIN
2 pkg.do_stuff;
3 END;
4 /
LexDepth Depth LineNo Name
——————— ——————— ———————— ——————————————————————————
0 6 2 __anonymous_block
1 5 21 PKG.DO_STUFF
2 4 18 PKG.DO_STUFF.NP1
3 3 15 PKG.DO_STUFF.NP1.NP2
4 2 12 PKG.DO_STUFF.NP1.NP2.NP3
0 1 12 FORMAT_CALL_STACK_12C
SQL> CREATE OR REPLACE FUNCTION backtrace_to
2 RETURN VARCHAR2
3 IS
4 BEGIN
5 RETURN
6 utl_call_stack.backtrace_unit (
7 utl_call_stack.error_depth)
8 || ' line '
9 ||
10 utl_call_stack.backtrace_line (
11 utl_call_stack.error_depth);
12 END;
13 /
SQL> CREATE OR REPLACE PACKAGE pkg1
2 IS
3 PROCEDURE proc1;
4 PROCEDURE proc2;
5 END;
6 /
SQL> CREATE OR REPLACE PACKAGE BODY pkg1
2 IS
3 PROCEDURE proc1
4 IS
5 PROCEDURE nested_in_proc1
6 IS
7 BEGIN
8 RAISE VALUE_ERROR;
9 END;
10 BEGIN
11 nested_in_proc1;
12 END;
13
14 PROCEDURE proc2
15 IS
16 BEGIN
17 proc1;
18 EXCEPTION
19 WHEN OTHERS THEN RAISE NO_DATA_FOUND;
20 END;
21 END pkg1;
22 /
SQL> CREATE OR REPLACE PROCEDURE proc3
2 IS
3 BEGIN
4 pkg1.proc2;
5 END;
6 /
SQL> BEGIN
2 proc3;
3 EXCEPTION
4 WHEN OTHERS
5 THEN
6 DBMS_OUTPUT.put_line (backtrace_to);
7 END;
8 /
HR.PKG1 line 19
- 顶
- 0
- 踩
- 0
PL/SQL精明的调用栈分析的更多相关文章
- Android群英传》读书笔记 (4) 第八章 Activity和Activity调用栈分析 + 第九章 系统信息与安全机制 + 第十章 性能优化
第八章 Activity和Activity调用栈分析 1.Activity生命周期理解生命周期就是两张图:第一张图是回字型的生命周期图第二张图是金字塔型的生命周期图 注意点(1)从stopped状态重 ...
- Android群英传笔记——第八章:Activity与Activity调用栈分析
Android群英传笔记--第八章:Activity与Activity调用栈分析 开篇,我们陈述一下Activity,Activity是整个应用用户交互的核心组件,了解Activity的工作模式,生命 ...
- PL/SQL程序中调用Java代码(转)
主要是学习PL/SQL调用JAVA的方法. 平台:WINDOWS 1.首先使用IDE写好需要调用的java代码,再添加"create or replace and compile java ...
- python错误处理—try…catch…finally、调用栈分析
高级语言包括python一般都内置了一套try…catch…finally的错误处理机制: >>> try: ... print('try...') ... r = 10 / 0 . ...
- 第四章 Activity和Activity调用栈分析 系统信息与安全机制 性能优化
1.Activity生命周期理解生命周期就是两张图:第一张图是回字型的生命周期图第二张图是金字塔型的生命周期图 注意点(1)从stopped状态重新回到前台状态的时候会先调用onRestart方法,然 ...
- C与lua交互--lua调用栈分析(2)
0 预备知识: 至少对Lua手册C API有简单的了解.lua5.3手册中文 1 Lua虚拟机的栈,如图: 假设虚拟机的栈有n个数据: 解释: 两种解释方式: A,栈顶开始, -1 ...-n B, ...
- Android组件内核之Activity调用栈分析(一)
阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680 导语 我们陈述一下Activity,Activity是整个应用用户交互的 ...
- 每周一书《Oracle 12 c PL(SQL)程序设计终极指南》
本周为大家送出的书是<Oracle 12 c PL(SQL)程序设计终极指南>,此书由机械工业出版社出版, 孙风栋,王澜,郭晓惠 著. 内容简介: <Oracle 12c PL/SQ ...
- PL/SQL数据库开发那点事
PL/SQL数据库开发那点事-->编程,存储程序 在SQL*plus 中编写PL/SQL程序,并在SQL*plus 中执行它, PL/SQL块的代码就存放在SQL*plus的缓冲区中.如果在SQ ...
随机推荐
- C++异常实现与longjmp, setjmp,栈指针EBP, Active Record
这篇讲的不错: http://blog.csdn.net/smstong/article/details/50728022 首先Active Record 然后EBP,ESP等指针 2 通过setjm ...
- Day5上午解题报告
预计分数:100+40+30=170 实际假分数:0+0+0=0 CE*3 实际真分数:60+50+0=110 老师没把我的程序放的文件夹里面,于是..... T1 https://www.luogu ...
- 【问题】VUE 同一页面路由参数变化,数据不刷新
依赖路由的params参数获取写在created生命周期里面,因为相同路由二次甚至多次加载的关系 没有达到监听,退出页面再进入另一个页面并不会运行created组件生命周期,导致数据还是第一次进入的数 ...
- 洛谷——P1443 马的遍历
https://www.luogu.org/problem/show?pid=1443#sub 题目描述 有一个n*m的棋盘(1<n,m<=400),在某个点上有一个马,要求你计算出马到达 ...
- ArcEngine标注和注记
转自原文 ArcEngine标注和注记 标注和注记是ArcEngine中提供的两种使用文字信息标注地图要素的方式.其中标注是作为图层的属性存在的,可以动态创建,注记作为地理要素被存储.需要注意的是Sh ...
- 强连通分量分解 Kosaraju算法 (poj 2186 Popular Cows)
poj 2186 Popular Cows 题意: 有N头牛, 给出M对关系, 如(1,2)代表1欢迎2, 关系是单向的且能够传递, 即1欢迎2不代表2欢迎1, 可是假设2也欢迎3那么1也欢迎3. 求 ...
- Linux系列-安装经常使用软件
安装JDK: 理论篇: 一.下载JDK 二.安装 ①复制到/usr/java/路径下 [plain] view plaincopy #mkdir /usr/java/ #cp jdk-7u25-lin ...
- Android学习笔记之按键操作
我们如何和Android 程序来进行交互那份?来让 Android 程序产生相应的反应,我们不得不通过键盘事件.触摸事件.传感器事件等来实现. 键盘是Android中主要的输入设备,对按键的响应的处理 ...
- 116.C语言异常抛错
#include <stdlib.h> #include <stdio.h> #include <setjmp.h> //异常抛错检测 jmp_buf buf1; ...
- Jszip的使用和打包下载图片
因为canvas总结到后面又想到了jszip的一些事情,那就索性也回去看看吧.试过,至少谷歌和火狐都是支持jszip的. 1. jszip的使用 官方文档说的很清楚了,而且也有读取zip文件.生成z ...