It is possible to debug PL/SQL Code in Oracle with DBMS_DEBUG. This article tries to show how to do that.
Additionally, there are a few SQL statements that can be called which should make it even easier to access adp_debug: These are:
|
This starts the debugger
|
|
This starts the debuggee
|
|
Continues after a breakpoint was hit
|
|
Aborts a debugging session
|
|
Steps to the next executable line
|
|
Shows the breakpoints
|
|
Deleteas a breakpoint
|
|
Is debugee running?
|
|
Steps into a function
|
|
Steps out of a function
|
|
Prints a variable's value
|
|
Sets a breakpoint
|
Ideally, these files should be stored in the directory specified with the environment variable SQLPATH so that they can be executed with ease.
Steps required to debugging a PL/SQL block
We want to debug the following pl/sql package:
create or replace package pkg_dbgd as
function tst_1(i in integer) return integer;
function tst_2(i in integer) return integer;
end pkg_dbgd;
/
The package specification:
create or replace package body pkg_dbgd as
function tst_1(i in integer) return integer is
begin
if i between 5 and 10 then
return 2*i;
end if;
if i between 0 and 4 then
return tst_2(3+i);
end if;
if i between 6 and 10 then
return tst_2(i-2);
end if;
return i;
end tst_1;
function tst_2(i in integer) return integer is
begin
if i between 6 and 8 then
return tst_1(i-1);
end if;
if i between 1 and 5 then
return i*2;
end if;
return i-1;
end tst_2;
end pkg_dbgd;
/
The debugee and the debugger
In order to debug PL/SQL with dbms_debug, two sessions are needed: a debugee session and a debugger session. The debugee session is the session in which the pl/sql code to be debugged is run while the debugger session controls the debugee, that is, the debugger sets breakpoints, clears them, continues the programm and queries variable's values.
Starting the debugee
The debugee is started with dbe:
Session altered.
START_DEBUGEE
----------------------------------------------------
0009000A0001
The string that is printed (0009000A0001 in this case) will be used when the debugger will be started.
Now, an anonymous PL/SQl is executed in the debugee session:
SQL> declare
2 v_result integer;
3begin
4 select pkg_dbgd.tst_1(4) into v_result from dual;
5end;
6/
After typing this in, the session seems to hang. That is because the debugee sessions waits for commands from the debugger session.
Starting the debugger
Now, an another session (called the debugger session) is attached to the debugee with dbr:
Enter value for debugee_id: 0009000A0001
Runtime Info
Prg Name:
Line:
Terminated: 0
Breakpoint:
Stackdepth
Interpr depth: 1
Reason: Interpreter is starting.
Namespace:Unknown namespace
Name:
owner:
dblink:
Line#:
lib unit:
entrypoint:
PL/SQL procedure successfully completed.
The debugee won't be touched until the end, all we do now is done in the debugger session.
Setting a breakpoint
With brl it is possible (and almost a must) to set a breakpoint. In the following case, the breakpoint is set on line 4:
Enter value for 1: 4
breakpoint set: 1
Running the debugee
It's time now to have the debugee run until it hits a breakpoint. cont will take care of that.
reason for break: Hit a breakpoint
1 declare
2 v_result integer;
3 begin
4 -> select pkg_dbgd.tst_1(4) into v_result from dual;
5 end;
6
7
8
9
As soon as a (or in our case the) breakpoint is hit, cont returns and we can enter new commands. cont also displays the line (+/- some preceeding and following lines) to make it easier to navigate in the code. The number of preceeding and following lines that are displayed are set with the package variables cont_lines_before_ and cont_lines_after_.
Stepping into
We want to know whats going on in pkg_dbgd_tst_1, so we step into this function using si:
reason for break: Procedure entry
RENE.PKG_DBGD
1 package body pkg_dbgd as
2 function tst_1(i in integer) return integer is
3 begin
4 -> if i between 5 and 10 then
5 return 2*i;
6 end if;
7
8 if i between 0 and 4 then
9 return tst_2(3+i);
Stepping
No, we step to the next executable line (with s:
adp_debug's package definition
adp_debug.sql
---------------------
-- 90 is the length in dbms_debug.vc2_table....
--create or replace type vc2_table as table of varchar2(90);
--/
create or replace package adp_debug as
procedure abort;
procedure backtrace;
-- highly expermiental
procedure current_prg;
procedure breakpoints;
procedure continue_(break_flags in number);
procedure continue;
procedure delete_bp(breakpoint in binary_integer);
procedure print_var(name in varchar2);
procedure start_debugger(debug_session_id in varchar2);
functionstart_debugee return varchar2;
procedure print_proginfo(prginfo dbms_debug.program_info);
procedure print_runtime_info(runinfo dbms_debug.runtime_info);
分享到:
Global site tag (gtag.js) - Google Analytics
|
相关推荐
Toad 是一款强大的数据库管理工具,...总之,使用Toad调试存储过程和触发器是一个高效的过程,它提供了直观的用户界面和强大的调试功能。遵循以上步骤,结合实际问题,你将能够有效地找出并修复PL/SQL代码中的问题。
对于开发者而言,调试存储过程是日常工作中不可或缺的一部分,尤其是在解决性能问题或错误时。标题提到的"sysbase调试脚本"可能指的是Oracle中的调试工具或方法。 Oracle提供了一种名为DBMS_DEBUG_JDWP的包,用于...
以下将详细介绍如何在Oracle环境中调试存储过程,包括调试的基本步骤、常用调试工具的使用,以及如何利用Oracle提供的调试特性来定位和解决代码中的错误。 ### Oracle存储过程调试方法 #### 1. 使用PL/SQL ...
10. **日志记录和调试**:通过DBMS_OUTPUT包记录过程执行信息,或者使用DBMS_DEBUG_JDWP包进行远程调试。 总的来说,Oracle存储过程是数据库管理和开发中的强大工具,它能够封装复杂的业务逻辑,提高代码复用性,...
Oracle提供DBMS_DEBUG_JDWP包进行远程调试,或者使用DBMS_OUTPUT.PUT_LINE打印调试信息。 十、存储过程在实际应用中的角色 在大型企业级应用中,存储过程常用于业务逻辑处理、数据转换、安全性控制、复杂查询优化等...
Oracle提供了一些工具如DBMS_DEBUG_JDWP包来进行远程调试,也可以使用`DBMS_OUTPUT.PUT_LINE`输出调试信息。 11. **Informix与Oracle存储过程的差异** Informix也有存储过程功能,但与Oracle相比,语法结构、变量...
- 调试工具:如DBMS_DEBUG_JDWP和DBMS_DEBUG_PC,用于远程调试PL/SQL代码。 - 性能分析:使用动态性能视图(如V$SESSION,V$SQL,V$SQLAREA等)监控SQL和PL/SQL执行情况。 - 优化器统计信息:定期收集和更新,...
其中,`DBMS_DEBUG_JDWP`包是Oracle提供的一种远程调试工具,允许开发者在运行时检查PL/SQL程序的状态。通过设置断点、查看变量值、跟踪调用堆栈等,你可以深入理解代码的执行流程,从而定位并解决问题。 关于LOB...
Oracle提供了DBMS_DEBUG_JDWP包来远程调试PL/SQL代码,或者通过DBMS_OUTPUT来打印中间结果辅助调试。在测试环境中,需要对存储过程进行充分的单元测试,确保所有可能的输入情况都得到了正确的处理。 在数据库迁移的...
在Oracle数据库中,触发器(Triggers)是一种存储过程,它们自动执行,当特定的数据库事件发生时,如INSERT、UPDATE或DELETE操作。调试Oracle触发器是开发和维护数据库应用程序时的重要步骤,可以帮助我们找出潜在的...
- **调试**:Oracle提供调试工具,如DBMS_DEBUG_JDWP,帮助定位和修复问题。 7. **标签"源码"和"工具"的关联** "源码"标签可能意味着文档中包含了存储过程的示例代码,而"工具"可能指的是Oracle提供的SQL ...
11. **存储过程的调试**:Oracle提供DBMS_DEBUG_JDWP包进行远程调试,或者使用SQL Developer等工具的内置调试器。 12. **存储过程的调用性能**:由于存储过程是预编译的,所以它们比多次执行单独的SQL语句更快。...
Oracle提供了一些工具和语法来帮助开发者调试存储过程,如`DBMS_DEBUG_JDWP`包用于远程调试,或者在PL/SQL代码中插入`DBMS_OUTPUT.PUT_LINE`来输出中间结果。 总之,Oracle的存储过程是数据库开发中的强大工具,...
- 开发存储过程通常在SQL*Plus环境中进行,通过编写SQL脚本文件(如`.sql`),然后在SQL*Plus中执行该脚本来创建、测试和调试存储过程。 5. **存储过程的运行**: - 使用`EXECUTE`语句来执行存储过程,如`EXECUTE...
4. **PL/SQL调试**:Oracle提供了一些内置的调试工具,如DBMS_DEBUG_JDWP包,用于远程调试PL/SQL代码。通过这些工具,开发者可以设置断点、查看变量值、跟踪代码执行流程等。 5. **PL/SQL实用程序**:可能包含一些...
调试PL/SQL程序的方法多种多样,包括使用DBMS_OUTPUT包来打印调试信息,设置断点,以及使用DBMS_DEBUG_JDWP包进行远程调试。这些工具帮助开发者跟踪代码执行流程,定位并修复潜在问题。 总的来说,Oracle PL/SQL是...
Oracle存储过程是数据库管理系统Oracle中的一个重要特性,...这个过程中涉及的知识点包括Oracle的加密机制、数据字典分析、动态性能视图的使用以及PL/SQL包的调试功能。解密过程应当谨慎进行,遵循合规性和安全性原则。
4. 使用Oracle的DBMS_DEBUG_JDWP包进行远程调试。 总之,Oracle存储过程是数据库编程的重要工具,熟练掌握其创建、调用和优化技巧,能够极大地提高数据库应用的效率和质量。在LINQ环境中,合理利用存储过程可以...
10. **存储过程的调试**:Oracle提供了一些内置的调试工具,如DBMS_DEBUG_JDWP,可以帮助开发者调试存储过程,查看变量值,跟踪代码执行流程。 这个“Oracle 存储过程资料集合”可能涵盖了这些概念的详细解释、实例...
在Oracle 11g R2中,你可以使用DBMS_DEBUG_JDWP包进行远程调试,或者利用DBA视图如ALL_PROCEDURES和USER_PROCEDURES来查看和管理存储过程。此外,可能还会讲解如何通过DDL语句ALTER PROCEDURE和DROP PROCEDURE来更新...