异常处理
Jun 07, 2016 pm 04:01 PM异常处理 一、预定义异常: Dup_val_on_index:试图向唯一索引列插入重复值,相当于建立了一个唯一索引 然后再向这个索引的列中插入一条重复的数据就会异常。 Invalid_cursors:试图进行非法的游标操作 Invalid_number : 试图将字符串转换为数字 no_data_found
异常处理
一、预定义异常:
Dup_val_on_index:试图向唯一索引列插入重复值,相当于建立了一个唯一索引 然后再向这个索引的列中插入一条重复的数据就会异常。
Invalid_cursors:试图进行非法的游标操作
Invalid_number : 试图将字符串转换为数字
no_data_found : select into 语句没有返回任何记录
Too_many_rows : select into 语句返回超过1条记录
Zero_divide : 试图除以 0
Cursor_already_open : 试图打开一个已经打开的游标
Others :包括所有异常
二、异常处理语法结构:
EXCEPTION --异常开始
WHEN 异常名1 THEN
--对应的异常处理
1、实例:
DECLARE
newSal emp.sal%TYPE;
BEGIN
select sal into newSal from emp;
EXCEPTION
when too_many_rows then --超过记录用too_many_rows
dbms_output.put_line('返回的记录太多了');
when others then --其他异常则输出
dbms_output.put_line('未知异常');
END;
三、自定义异常:
DECLARE
newSal emp.sal%TYPE;
myexp exception; --声明异常变量
BEGIN
select sal into newSal from emp where rownum=1;
if newsal>500 then --情况出现时就调用异常
raise myexp;
end if;
EXCEPTION
when too_many_rows then --超过记录用too_many_rows
dbms_output.put_line('返回的记录太多了');
when myexp then
dbms_output.put_line('工资不能超过500');
when others then --其他异常则输出
dbms_output.put_line('未知异常');
END;

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The operation process of WIN10 service host occupying too much CPU

What is Discuz? Definition and function introduction of Discuz

MIT's latest masterpiece: using GPT-3.5 to solve the problem of time series anomaly detection

A guide to the unusual missions in the Rise of Ronin Pool

Learn how to handle special characters and convert single quotes in PHP

How to solve sound card driver abnormality

C++ function exceptions and single testing: ensuring code soundness
