zoukankan      html  css  js  c++  java
  • Oracle笔记:pl/sql例外处理

    例外的分类:
    1) 预定义例外:由pl/sql提供的系统例外,当pl/sql应用程序违反了oracle规定的限制时,则会隐含地触发一个内部例外。
    例:
    --编写一个块,可接收雇员的编号,并显示该雇员的姓名。
    declare
    v_ename emp.ename%type;
    begin
    select ename into v_ename from emp where empno=&no;
    dbms_output.put_line('名字:'||v_ename);
    exception
    when no_data_found then
    dbms_output.put_line('输入的编号有误!');
    end;

    2) 非预定义例外:用于处理预定义例外不能处理的oracle错误例外。

    3) 自定义例外:用于处理与oracle错误无关的其它情况。例:
    --编写一个过程,接收一个雇员的编号,并给该雇员工资增加1000元
    --如果该雇员不存在则给出相应提示。
    create or replace procedure test_ex(testNO number)
    is
    --定义一个例外
    testEx exception;
    begin
    update emp set sal=sal+1000 where empno=testNO;
    --sql%notfound表示没有update
    --raise testEx表示触发testEx
    if sql%notfound then
    raise testEx;
    end if;
    exception
    when testEx then
    dbms_output.put_line('没有更新任何数据!');
    end;

  • 相关阅读:
    sharepoint 2013 configure my site
    格式化xml
    斗罗大陆
    spring的beans.xml的配置
    jdom学习:读取xml文件
    java中加载xml文件方法
    struts2中IOC控制反转应用
    struts2.xml的配置与技巧
    struts2中的路径问题
    struts.xml详细配置
  • 原文地址:https://www.cnblogs.com/testing/p/3013496.html
Copyright © 2011-2022 走看看