Oracle中调试存储过程


本人在写存储过程时,不知道如何调试它。 有一种调试办法就是在程序中打印出变量的值,在JAVA中俺是打印在控制台上的。以下告诉众位如何从在sqlplus上实现。

1、sqlplus 上执行 “set serveroptput on”命令

2、在存储过程中可以用 DBMS_OUTPUT.PUT_LINE(VarName); 来打印出来

给个存储过程的例子:

create or replace procedure test is

Emp_name VARCHAR2(10);
Cursor c1 IS SELECT Ename FROM EMP
WHERE Deptno = 20;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO Emp_name;
EXIT WHEN c1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(Emp_name);
END LOOP;

end test;

后台建立test这个存储过程,编译它,以scott/tiger帐号进入,执行set serveroptput on,然后执行“exec test”

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus