• Oracle异常的抛出处理


    --一异常处理的代码
    --sqlcode 异常编号
    --sqlerrm 信号字符串
    
    /*
    
    在plsql 块中格式
    
    Declare
      变量
    Begin
        代码块
        
        EXCEPTION
            when 异常的名称  then
                如生上面的异常时做的具体工作。
    End;
    
    */
    
    set serveroutput on;
    create or replace procedure pr12
    as
    --定义一个int变liang
    v_age integer;
    v_name varchar(30);
    begin 
    v_age:=89;
    --通过select给v_name设置值
    --修改成过程
    select name into v_name from stud where id=1;
    DBMS_OUTPUT.PUT_LINE('没有出错');
    exception
     when value_error then 
     SYS.DBMS_OUTPUT.PUT_LINE('数值错误');
     when no_data_found then 
     SYS.DBMS_OUTPUT.PUT_LINE('没有数据');
     when others then
     SYS.DBMS_OUTPUT.PUT_LINE(sqlcode||'你出错了'||sqlerrm);
     end;
    
    exec pr12();
    -----------------------------------------
    --自定义异常自己抛出异常/
    /*
    定义一个自己的异常
          myException Exception;
    抛出异常
        RAISE myException;
        
        处理自己的异常:
            Exception 
                When myException then
                    ....
    */
    set serveroutput on;
    declare
    myEx exception;
    begin
    DBMS_OUTPUT.PUT_LINE('这里没错');
    raise myEx;
    DBMS_OUTPUT.PUT_LINE('不会输出,前面抛出异常');
    --处理异常
    exception
    when myEx then
    DBMS_OUTPUT.PUT_LINE('自己的异常'||sqlcode||'  '||sqlerrm);
    when others then 
    DBMS_OUTPUT.PUT_LINE('不知知道什么错误'||sqlcode||sqlerrm);
    END;
    ---出错直接抛出
    
    declare
    begin
    DBMS_OUTPUT.PUT_LINE('no errors');
    --直接抛出
    RAISE_APPLICATION_ERROR(-20000, 'A');
    DBMS_OUTPUT.PUT_LINE('go okk....');
    exception
       when others then
    DBMS_OUTPUT.PUT_LINE(sqlcode||'  '||sqlerrm);
    end;
  • 相关阅读:
    爬虫_requests
    第十四周总结
    《三个和尚》观看感悟
    第十三周总结
    ThinkPHP
    ThinkPHP配置安装
    ThinkPHP_1
    构建之法阅读笔记六
    网络工程师必备学习内容!深度理解OSPF——OSPF是什么?为什么要用OSPF?
    网络工程师学习笔记——RIP路由汇总实验配置
  • 原文地址:https://www.cnblogs.com/xiaweifeng/p/3677058.html
Copyright © 2020-2023  润新知