zoukankan      html  css  js  c++  java
  • Oracle用户自定义异常

    注意:普通的查询语句不会出现异常,只有使用into对变量进行赋值的时候才会发生异常

    1 --系统变量: notfound  --> if sql%notfund then 如果这个表达式为真,则 (增删改)出错
    2 --,先自定义一个异常:no_result exception
    3                 -- if sql%nofund then
    4                 --excetpion
    5                     --when no_result then 
    6                     --dbms……

    用户自定义异常写在:declare里,如:

    1 set serveroutput on
    2 declare
    3 no_result exception; --自定义异常
    4 v_ssid student_test.sid%type;
     1 begin
     2    update student_test set sex='' where sid=1000002;   --没有异常,报(自定义异常)插入为空的错误
     3   if SQL%NOTFOUND then
     4     RAISE no_result;
     5   end if;
     6 exception
     7   when no_result then
     8     dbms_output.put_line('修改有误!');
     9   when dup_val_on_index then
    10     dbms_output.put_line('系统异常,违反主键约束');
    11 end;

    如果修改语句修改为空,系统不会报错,但会直接进入用户自己定义的no_result异常里,

    if SQL%NOTFOUND then
        RAISE no_result;
    end if;
    SQL%NOTFOUND是检查更新语句是否更新成功,如果更新失败,则notfound语句为真,
    则使用raise语句跳转到no_result异常执行。

    (dup_val_on_index)异常是系统异常,如果使用插入语句并且违反主键唯一性约束,
    则执行dup_val_on_index异常。
  • 相关阅读:
    17_8_30 Mybatis 入门
    17_8_29 mysql 导入导出备份还原
    [iOS基础控件
    [iOS基础控件
    [iOS基础控件
    [MAC OSX
    [iOS基础控件
    [iOS基础控件
    [iOS基础控件
    [iOS基础控件
  • 原文地址:https://www.cnblogs.com/lwl80/p/13253853.html
Copyright © 2011-2022 走看看