异常处理

Jun 07, 2016 pm 04:01 PM
index val deal with definition abnormal

异常处理 一、预定义异常: 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;

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What file is index.html? What file is index.html? Feb 19, 2024 pm 01:36 PM

What file is index.html?

The operation process of WIN10 service host occupying too much CPU The operation process of WIN10 service host occupying too much CPU Mar 27, 2024 pm 02:41 PM

The operation process of WIN10 service host occupying too much CPU

What is Discuz? Definition and function introduction of Discuz What is Discuz? Definition and function introduction of Discuz Mar 03, 2024 am 10:33 AM

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 MIT's latest masterpiece: using GPT-3.5 to solve the problem of time series anomaly detection Jun 08, 2024 pm 06:09 PM

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 A guide to the unusual missions in the Rise of Ronin Pool Mar 26, 2024 pm 08:06 PM

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

Learn how to handle special characters and convert single quotes in PHP Learn how to handle special characters and convert single quotes in PHP Mar 27, 2024 pm 12:39 PM

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

How to solve sound card driver abnormality How to solve sound card driver abnormality Feb 22, 2024 am 09:10 AM

How to solve sound card driver abnormality

C++ function exceptions and single testing: ensuring code soundness C++ function exceptions and single testing: ensuring code soundness May 03, 2024 am 09:18 AM

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

See all articles