Oracle数据库数据恢复、性能优化

找回密码
注册
搜索
热搜: 活动 交友 discuz
发新帖

0

积分

0

好友

1

主题
1#
发表于 2012-12-7 17:55:07 | 查看: 2778| 回复: 1
本帖最后由 keepLearning 于 2012-12-7 17:56 编辑

create or replace procedure scott.p_test
is
begin
insert into scott.emp(empno,ename,deptno) values(12,'bsd',33);
commit;
exception
  when others then
    ROLLBACK;
    dbms_output.put_line('SQLCODE:  '||SQLCODE);
    dbms_output.put_line('SQLERRM:  '||SQLERRM);
end;
如果是如上代码只能获取到一个错误提示
SQL> set serverout on;
SQL> exec scott.p_test;

SQLCODE:  -2291
SQLERRM:  ORA-02291: integrity constraint (SCOTT.FK_DEPTNO) violated - parent key not found

PL/SQL procedure successfully completed




如果是下面代码sqlplus就会给所以错误提示,包括行定位
ORA-02291: integrity constraint (SCOTT.FK_DEPTNO) violated - parent key not found
ORA-06512: at "SCOTT.P_TEST", line 4
ORA-06512: at line 2




create or replace procedure scott.p_test
is
begin
insert into scott.emp(empno,ename,deptno) values(12,'bsd',33);
commit;
/*exception
  when others then
    ROLLBACK;
    dbms_output.put_line('SQLCODE:  '||SQLCODE);
    dbms_output.put_line('SQLERRM:  '||SQLERRM);*/
end;

2#
发表于 2012-12-7 19:42:09
FYI


  1. SQL> create table emp(empno int primary key, ename varchar2(2000),depno int);

  2. Table created.


  3. SQL> insert into emp values(1,'maclean',2);

  4. 1 row created.

  5. SQL> commit;

  6. Commit complete.

  7. SQL> set serveroutput on;


  8. create or replace procedure p_test
  9. is
  10. begin
  11. insert into emp(empno,ename,depno) values(1,'maclean',3);
  12. commit;
  13. exception
  14.   when others then
  15.     ROLLBACK;
  16.     dbms_output.put_line('SQLCODE:  '||SQLCODE);
  17.     dbms_output.put_line('SQLERRM:  '||SQLERRM);
  18. end;
  19. /

  20. SQL> exec p_test;
  21. SQLCODE:  -1
  22. SQLERRM:  ORA-00001: unique constraint (SYS.SYS_C004814) violated

  23. PL/SQL procedure successfully completed.


  24. create or replace procedure p_test
  25. is
  26. begin
  27. insert into emp(empno,ename,depno) values(1,'maclean',3);
  28. commit;
  29. exception
  30.   when others then
  31.     ROLLBACK;
  32.     dbms_output.put_line('SQLCODE:  '||SQLCODE);
  33.     dbms_output.put_line('SQLERRM:  '||SQLERRM);
  34.        
  35.         DBMS_OUTPUT.PUT_LINE( DBMS_UTILITY.FORMAT_ERROR_BACKTRACE );
  36. end;
  37. /




  38. SQL> exec p_test;
  39. SQLCODE:  -1
  40. SQLERRM:  ORA-00001: unique constraint (SYS.SYS_C004814) violated
  41. ORA-06512: at "SYS.P_TEST", line 4
复制代码
keepLearning 发表于 2012-12-10 14:31
谢谢,我把DBMS_UTILITY下的包全面学习一下。
您需要登录后才可以回帖 登录 | 注册

QQ|手机版|Archiver|Oracle数据库数据恢复、性能优化

GMT+8, 2024-11-16 03:48 , Processed in 0.052810 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部
TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569