zoukankan      html  css  js  c++  java
  • oracle使用异常

    RAISE_APPLICATION_ERROR :把异常信息返回给调用的客户端
    RAISE_APPLICATION_ERROR( error_number_in IN NUMBER, error_msg_in IN VARCHAR2);
    error_number_in 只允许从 -20000 到 -20999 之间,这样就不会与 ORACLE 的任何错误代码发生冲突。error_msg_in 的长度不能超过 2k,否则截取 2k。

    -- 建表
    create table temp_age(
    age_id number(5),
    age number(3)
    );
    -- 建触发器
    create or replace trigger t_temp_age_check

    before insert on temp_age
     
      for each row
        begin
          if :new.age < 18
            then
              raise_application_error(-20001,'age must at least 18 years old');
     
            end if;
     
        end;
    -- 客户端程序
    declare
    no_baby_allowed exception;
    pragma exception_init(no_baby_allowed,-20001);
    begin
         insert into temp_age(age_id,age) values(1,20);
         insert into temp_age(age_id,age) values(2,17);
        insert into temp_age(age_id,age) values(3,18);
        exception
            when no_baby_allowed
                then
                    dbms_output.put_line(sqlerrm);
    end;

    客户端程序执行输出结果:
    ORA-20001: age must at least 18 years old
    ORA-06512: 在 "LCAM_DEVELOP.T_TEMP_AGE_CHECK", line 4
    ORA-04088: 触发器 'LCAM_DEVELOP.T_TEMP_AGE_CHECK' 执行过程中出错

    参考博客:https://blog.csdn.net/daxiang12092205/article/details/19753297

  • 相关阅读:
    第六天
    《分布式架构中数据一致性常见的几个问题》阅读心得
    第五天
    软件开发记录第四天
    资料整理
    Mongodb_分片集群模式
    MongoDB_spring整合mongodb
    安装环境
    MongoDB_副本集集群模式
    MongoDB_java连接MongoDB
  • 原文地址:https://www.cnblogs.com/cyf18/p/14285502.html
Copyright © 2011-2022 走看看