二十二、Oracle学习笔记:Oracle异常
发布日期:2021-07-26 07:20:45
浏览次数:3
分类:技术文章
本文共 1427 字,大约阅读时间需要 4 分钟。
一、Oralce异常
1.Oracle低层定义了很多异常,每个异常都有一个唯一的编码,这些异常之中,有一些是比较常见的,ORACLE 给这些异常定义了名称,可以直接使用,其他没有名称只有编码的不能直接使用。 2.异常的分类 (1)预定义异常 既有编码又有名称的异常是预定义异常,此类异常可以直接使用 (2)非预定义异常 有编码但没有名称的异常是非预定义异常,此类异常不能直接使用,要想使用需要先声明一个异常名与代码绑定 (3)自定义异常 既没有编码也没有名称的异常时自定义异常,此类异常需要我们自己定义3.异常的使用
(1)预定义异常的使用--格式: exception when 异常名 then --异常处理--练习:使用too_many_rows预定义异常:多对一的情况,将一个字段多个值存入一个变量 declare sal_a emp.sal%type; begin select sal into sal_a from emp; exception when too_many_rows then dbms_output.put_line('多行对一行,出现异常'); end; /(2)非预定义异常的使用
--格式: declare --声明异常 异常名 exception --绑定异常编码 pragma exception_init(异常名,编码); begin exception when 异常名 then --异常处理 end; / --练习,使用-01407非预定义异常(此编码是修改主键为null发生的异常编码) declare null_id exception; pragma exception_init(null_id,-01407); begin update emp set empno=null where empno=1001; exception when null_id then dbms_output.put_line('主键为空'); end; /
(3)自定义异常的使用
--格式: declare --声明异常 异常名 exception; begin --某条件发生时,抛出异常 raise 异常名; exception when 异常名 then --异常处理 end; /--练习:定义进入浴池的年龄:大于18岁 create or replace function isOrNot(age number) return number is age18 exception; begin if age<18 then raise age18; end if; return age; exception when age18 then dbms_output.put_line('你不能进入浴池'); return 0; end; declare a number; begin a:=isOrNot(16); end; /
转载地址:https://blog.csdn.net/qq_38741971/article/details/81429367 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
网站不错 人气很旺了 加油
[***.192.178.218]2024年04月17日 02时08分17秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
datagrid的正反双向排序
2019-04-27
在分页状态下删除纪录的问题
2019-04-27
使用DataGrid动态绑定DropDownList
2019-04-27
DataGrid删除确认及Item颜色交替
2019-04-27
NetBeans配置Xdebug 远程调试PHP
2019-04-27
MediaWiki安装
2019-04-27
Squid安装
2019-04-27
如何查看当前Linux的版本
2019-04-27
Ubuntu安装Nginx
2019-04-27
Ubuntu 下安装thttpd Web服务器
2019-04-27
用thttpd做Web Server
2019-04-27
服务器端开发经验总结 Linux C语言
2019-04-27
将网站程序放在tmpfs下
2019-04-27
使用Nginx的proxy_cache缓存功能取代Squid
2019-04-27
nginx 反向代理,动静态请求分离,proxy_cache缓存及缓存清除
2019-04-27
nginx 的proxy_cache才是王道
2019-04-27
Nginx proxy_cache 使用示例
2019-04-27
Nginx源代码分析 - 日志处理
2019-04-27
使Apache实现gzip压缩
2019-04-27
Memcached在大型网站中应用
2019-04-27