【问题标题】:integrity constraint violated - child record found exception违反完整性约束 - 发现子记录异常
【发布时间】:2015-07-10 19:32:12
【问题描述】:

当我收到错误 ORA-02292:违反完整性约束 - 找到子记录时,我想在我的网站上显示一条警报(对不起,但这种类型无法删除)消息。如何创建该异常?来自 php 或来自数据库,究竟如何?

我试过这样的

begin
  -- Test statements here   
        DELETE FROM PETTYPE
        WHERE PET_TYPE_CODE = 40;
        COMMIT; 
EXCEPTION 
       WHEN CHILD_RECORD_FOUND  
       THEN Dbms_Output.put_line('ERROR'); 


end; 

但它不起作用,因为 child_record_found 没有声明。

任何建议将不胜感激! :)

【问题讨论】:

    标签: php oracle exception error-handling


    【解决方案1】:

    你可以当别人用,

    create table ref1 ( a int primary key);
    create table ref2 (a int references ref1(a));
    
    SQL> select * from ref1;
    
             A
    ----------
             1
             2
    
    SQL> select * from ref2;
    
             A
    ----------
             1
             2
    
    set serveroutput on
    
    SQL>    declare
      2     begin
      3    -- Test statements here
      4          DELETE FROM REF1
      5          WHERE a = 1;
      6          COMMIT;
      7  EXCEPTION
      8         WHEN others then
      9          Dbms_Output.put_line('Im sorry but this type cannot be deleted');
     10
     11
     12  end;
     13  /
    Im sorry but this type cannot be deleted
    
    PL/SQL procedure successfully completed.
    

    【讨论】:

      【解决方案2】:

      您可以使用 PRAGMA EXCEPTION_INIT 声明将您自己的异常类型与内部 Oracle 错误号相关联。文档:http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/errors.htm#BABGIIBI

      【讨论】:

        猜你喜欢
        • 2012-06-18
        • 2013-03-31
        • 2017-05-17
        • 2019-03-16
        • 2015-02-24
        • 1970-01-01
        • 2020-01-14
        • 2015-11-26
        相关资源
        最近更新 更多