首页 > 数据库技术 > 详细

Oracle PL/SQL学习之基础篇(2)--例外

时间:2018-07-18 00:25:34      阅读:255      评论:0      收藏:0      [点我收藏+]

1、例外分类:系统例外、自定义例外

    (1)系统例外,参见相关API文档

    (2)自定义例外

         定义自己的例外:就像自定义变量一样,类型为exception

        抛出例外:使用raise抛出自定义例外

set serveroutput on
declare
    cursor cemp is select ename from emp where deptno=50;
    
    pename emp.ename%type;
    
    --self define exception
    self_no_data_found exception;
begin
    open cemp;
    
    fetch cemp into pename;
    if cemp%notfound then
        --throw self define exception
        raise self_no_data_found;
    end if;
exception
   when self_no_data_found then
      dbms_output.put_line(执行了自定义异常!);
      if cemp%isopen then
         dbms_output.put_line(close cursor!);
         close cemp;
      end if;
   when others then
      dbms_output.put_line(执行了others异常!);
      if cemp%isopen then
         close cemp;
      end if;
end;
/

运行结果:

技术分享图片

 

Oracle PL/SQL学习之基础篇(2)--例外

原文:https://www.cnblogs.com/ZeroMZ/p/9326749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!