zoukankan      html  css  js  c++  java
  • 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;
  • 相关阅读:
    Ubuntu设置静态IP,解决重启后需要重新设置的问题。
    Ubuntu网速慢的问题
    WinPcap编程4——捕获数据包
    有关汇编的文章与代码
    WinPcap编程1——简介
    野外生活完全攻略
    户外与学习方法
    躲猫猫是什么意思
    C++各大有名库的介绍——综合
    WinPcap编程3——获取网络适配器列表
  • 原文地址:https://www.cnblogs.com/xiaweifeng/p/3677058.html
Copyright © 2011-2022 走看看