exception
SQL> -- 例外 exception
SQL> -- 1/0
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 begin
4 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
5 exception
6 when zero_divide then dmms_output.put_line('不能被0除');
7* end;
8 ed
9 /
ed
*
第 8 行出现错误:
ORA-06550: 第 8 行, 第 1 列:
PLS-00103: 出现符号 "ED"符号 "ED" 被忽略。
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 begin
4 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
5 exception
6 when zero_divide then dbms_output.put_line('不能被0除');
7* end;
SQL> /
不能被0除
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 begin
4 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
5* end;
6 /
declare
*
第 1 行出现错误:
ORA-01476: 除数为 0
ORA-06512: 在 line 4
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 begin
4 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
5 exception
6 when zero_divide then dbms_output.put_line('不能被0除')
7* end;
SQL> /
end;
*
第 7 行出现错误:
ORA-06550: 第 7 行, 第 1 列:
PLS-00103: 出现符号 "END"在需要下列之一时:
:= . ( % ;
符号 ";" 被替换为 "END" 后继续。
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 begin
4 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
5 exception
6 when zero_divide then dbms_output.put_line('不能被0除');
7* end;
SQL> /
不能被0除
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 pname emp.ename%type;
4 begin
5 select ename into pname from emp;
6 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
7 exception
8 when zero_divide then dbms_output.put_line('不能被0除');
9* end;
SQL> /
declare
*
第 1 行出现错误:
ORA-01422: 实际返回的行数超出请求的行数
ORA-06512: 在 line 5
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 pname emp.ename%type;
4 begin
5 select ename into pname from emp;
6 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
7 exception
8 when zero_divide then dbms_output.put_line('不能被0除');
9 when too_many_rows then dbms_output.put_line('太多的行');
10* end;
SQL> /
太多的行
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 pname emp.ename%type;
4 begin
5 select ename into pname from emp;
6 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
7 exception
8 when zero_divide then dbms_output.put_line('不能被0除');
9 when too_many_rows then dbms_output.put_line('太多的行');
10 when others then dbms_output.put_line('qita');
11* end;
SQL> /
太多的行
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 declare
2 pnum number := 0;
3 pname emp.ename%type;
4 begin
5 select ename into pname from emp;
6 pnum := 1/pnum; -- 会跑出一个叫zero_divide的异常
7 exception
8 when zero_divide then dbms_output.put_line('不能被0除');
9 when others then dbms_output.put_line('qita');
10* end;
SQL> /
qita
PL/SQL 过程已成功完成。
SQL> -- 自定义列外
SQL> ed
已写入 file afiedt.buf
1 -- 查询50号部门的所有员工的姓名,如果没有查到数据跑出列外
2 declare
3 cursor cemp is select ename from emp where deptno = 50;
4 pname emp.ename%type;
5 -- 自己定义异常
6 not_emp_data exception;
7 begin
8 open cursor;
9 if cemp%notfound then raise not_emp_data;
10 else
11 loop
12 fetch cemp into pname;
13 exit when cemp%notfound;
14 dbms_output.put_line(pname);
15 end loop;
16 end if;
17 close cursor;
18 exception
19 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
20* end;
21 /
if cemp%notfound then raise not_emp_data;
*
第 9 行出现错误:
ORA-06550: 第 8 行, 第 7 列:
PLS-00201: 必须声明标识符 'CURSOR'
ORA-06550: 第 8 行, 第 2 列:
PL/SQL: SQL Statement ignored
ORA-06550: 第 17 行, 第 8 列:
PLS-00201: 必须声明标识符 'CURSOR'
ORA-06550: 第 17 行, 第 2 列:
PL/SQL: SQL Statement ignored
SQL> ed
已写入 file afiedt.buf
1 -- 查询50号部门的所有员工的姓名,如果没有查到数据跑出列外
2 declare
3 cursor cemp is select ename from emp where deptno = 50;
4 pname emp.ename%type;
5 -- 自己定义异常
6 not_emp_data exception;
7 begin
8 open cemp;
9 if cemp%notfound then raise not_emp_data;
10 else
11 loop
12 fetch cemp into pname;
13 exit when cemp%notfound;
14 dbms_output.put_line(pname);
15 end loop;
16 end if;
17 close cursor;
18 exception
19 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
20* end;
SQL> ed
已写入 file afiedt.buf
1 -- 查询50号部门的所有员工的姓名,如果没有查到数据跑出列外
2 declare
3 cursor cemp is select ename from emp where deptno = 50;
4 pname emp.ename%type;
5 -- 自己定义异常
6 not_emp_data exception;
7 begin
8 open cemp;
9 if cemp%notfound then raise not_emp_data;
10 else
11 loop
12 fetch cemp into pname;
13 exit when cemp%notfound;
14 dbms_output.put_line(pname);
15 end loop;
16 end if;
17 close cemp;
18 exception
19 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
20* end;
SQL> /
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 -- 查询50号部门的所有员工的姓名,如果没有查到数据跑出列外
2 set serveroutput on
3 declare
4 cursor cemp is select ename from emp where deptno = 50;
5 pname emp.ename%type;
6 -- 自己定义异常
7 not_emp_data exception;
8 begin
9 open cemp;
10 if cemp%notfound then raise not_emp_data;
11 else
12 loop
13 fetch cemp into pname;
14 exit when cemp%notfound;
15 dbms_output.put_line(pname);
16 end loop;
17 end if;
18 close cemp;
19 exception
20 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
21* end;
SQL> /
cursor cemp is select ename from emp where deptno = 50;
*
第 4 行出现错误:
ORA-00922: 选项缺失或无效
SQL> ed
已写入 file afiedt.buf
1 -- 查询50号部门的所有员工的姓名,如果没有查到数据跑出列外
2 declare
3 cursor cemp is select ename from emp where deptno = 50;
4 pname emp.ename%type;
5 -- 自己定义异常
6 not_emp_data exception;
7 begin
8 open cemp;
9 if cemp%notfound then raise not_emp_data;
10 else
11 loop
12 fetch cemp into pname;
13 exit when cemp%notfound;
14 dbms_output.put_line(pname);
15 end loop;
16 end if;
17 close cemp;
18 exception
19 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
20* end;
SQL> set serveroutput on;
SQL> -- 查询50号部门的所有员工的姓名,如果没有查到数据跑出列外
SQL> declare
2 cursor cemp is select ename from emp where deptno = 50;
3 pname emp.ename%type;
4 -- 自己定义异常
5 not_emp_data exception;
6 begin
7 open cemp;
8 if cemp%notfound then raise not_emp_data;
9 else
10 loop
11 fetch cemp into pname;
12 exit when cemp%notfound;
13 dbms_output.put_line(pname);
14 end loop;
15 end if;
16 close cemp;
17 exception
18 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
19 end;
20 /
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 declare
2 cursor cemp is select ename from emp where deptno = 50;
3 pname emp.ename%type;
4 -- 自己定义异常
5 not_emp_data exception;
6 begin
7 open cemp;
8 if cemp%notfound then
9 dbms_output.put_line('11');
10 raise not_emp_data;
11 else
12 loop
13 fetch cemp into pname;
14 exit when cemp%notfound;
15 dbms_output.put_line(pname);
16 end loop;
17 end if;
18 close cemp;
19 exception
20 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
21* end;
SQL> /
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 declare
2 cursor cemp is select ename from emp where deptno = 50;
3 pname emp.ename%type;
4 -- 自己定义异常
5 not_emp_data exception;
6 begin
7 open cemp;
8 fetch cemp into pname;
9 if cemp%notfound then
10 dbms_output.put_line('11');
11 raise not_emp_data;
12 else
13 loop
14 exit when cemp%notfound;
15 dbms_output.put_line(pname);
16 end loop;
17 end if;
18 close cemp;
19 exception
20 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
21* end;
SQL> /
11
没有找到50号部门的数据
PL/SQL 过程已成功完成。
SQL> ed
已写入 file afiedt.buf
1 declare
2 cursor cemp is select ename from emp where deptno = 50;
3 pname emp.ename%type;
4 -- 自己定义异常
5 not_emp_data exception;
6 begin
7 open cemp;
8 fetch cemp into pname;
9 if cemp%notfound then
10 dbms_output.put_line('11');
11 raise not_emp_data;
12 else
13 loop
14 exit when cemp%notfound;
15 dbms_output.put_line(pname);
16 end loop;
17 end if;
18 close cemp;
19 exception
20 when not_emp_data then dbms_output.put_line('没有找到50号部门的数据');
21* end;
SQL> /
11
没有找到50号部门的数据
PL/SQL 过程已成功完成。
SQL> select sum(sal) from emp;
SUM(SAL)
----------
47025
SQL> spool off;
exception的更多相关文章
- [C#] C# 知识回顾 - 你真的懂异常(Exception)吗?
你真的懂异常(Exception)吗? 目录 异常介绍 异常的特点 怎样使用异常 处理异常的 try-catch-finally 捕获异常的 Catch 块 释放资源的 Finally 块 一.异常介 ...
- 浅谈java异常[Exception]
学习Java的同学注意了!!! 学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入Java学习交流群,群号码:589809992 我们一起学Java! 一. 异常的定义 在<java编程思想 ...
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
学习架构探险,从零开始写Java Web框架时,在学习到springAOP时遇到一个异常: "C:\Program Files\Java\jdk1.7.0_40\bin\java" ...
- Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...
- Atitit 解决Unhandled event loop exception错误的办法
Atitit 解决Unhandled event loop exception错误的办法 查看workspace/.metadata/.log org.eclipse.swt.SWTError: No ...
- Java中的Checked Exception——美丽世界中潜藏的恶魔?
在使用Java编写应用的时候,我们常常需要通过第三方类库来帮助我们完成所需要的功能.有时候这些类库所提供的很多API都通过throws声明了它们所可能抛出的异常.但是在查看这些API的文档时,我们却没 ...
- Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.
启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...
- Android开发学习之路-关于Exception
Exception在Java中是表示异常的一个类.它是Throwable的子类. 而Exception的子类RuntimeException是一个特殊的异常类,在代码中不需要对此类进行throw,而是 ...
- 严重: Exception sending context initialized event to listener instance of class
问题描述:Exception sending context initialized event to listener instance of class org.springframework.w ...
- python之最强王者(11)——异常(exception)
1.Python 异常处理 python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误.你可以使用该功能来调试python程序. 异常处理: 本站Python教程会具体介绍. ...
随机推荐
- centos安装配置amoeba以及测试
一.amoeba介绍网址:http://docs.hexnova.com/amoeba/ 二.安装java se1.5 三.安装amoeba2.2.01.下载地址:http://sourceforge ...
- Thinking in Java——笔记(4)
Controlling Execution true and false Java doesn't allow you to use a number as a boolean. If you wan ...
- SevenZip.pas BUG修改版 - 20160613
原始版本: Henri Gourvest <hgourvest@gmail.com> 1.2版本 BUG修改: 1.对于文件名中带有空格的文件, 无法压缩, 原因是1488行, 压缩调用的 ...
- play for scala 通过网易smtp发送邮件
最近用play来做一个小项目,里面用到了发送邮件的功能.这里我将这部分抽出来分享,毕竟目前来看paly于scala方面的中文资料在网上还是毕竟少,希望我的这篇文章能为有需要的人提供一点思路. 下面写下 ...
- ES6 module export options 模块导出、导入语法
http://stackoverflow.com/questions/25494365/es6-module-export-options A year and some later, here is ...
- Redis的Python客户端redis-py
1. 安装 1. redis-py a. 使用easy_install 1 sudo easy_install redis b. 源码安装 1 2 3 git clone https://githu ...
- 简单粗暴下载Spring
http://repo.springsource.org/libs-release-local/org/springframework/spring/4.3.3.RELEASE/(想要下载什么版本,替 ...
- Python开发【第七章】:Python异常处理
一.异常处理 1.异常基础 在编程过程中为了增加友好性,在程序出现bug时一般不会将错误信息显示给用户,而是现实一个提示的页面,通俗来说就是不让用户看见大黄页!!! #异常处理 list = [&qu ...
- $.each()
以下内容非原创 通过它,你可以遍历对象.数组的属性值并进行处理. 使用说明 each函数根据参数的类型实现的效果不完全一致: 1.遍历对象(有附加参数) $.each(Object, function ...
- paper 107:图像的白平衡
所谓白平衡(White Balance):指在图像处理的过程中,对原本材质为白色的物体的图像进行色彩还原,去除外部光源色温的影响,使其在照片上也显示白色.也就是不管在任何光源下,都能将白色物体还原为白 ...