ORACLE中的异常处理
2009-04-09 15:49
357 查看
1、ORALCE自带一些命名的系统异常,如下:
2、也可以采用自定义的异常的名字:
declare
myexception exception;
begin
if 1<>2 then
raise myexception;
end if;
exception
when myexception then
/*注:raise_application_error的语法为raise_application_error(erorcd in int,erortx in varchar 2),其中erorcd的值为20001到20999*/
raise_application_error(20001,'my exception happens');
when others then
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
end
3、存储过程可能要涉及到层层调用,因此在每一次都需要写异常处理,这让程序会更健壮。
本文出自:冯立彬的博客
Oracle Exception Name | Oracle Error | Explanation | 中文注释 |
DUP_VAL_ON_INDEX | ORA-00001 | You tried to execute an INSERT or UPDATE statement that has created a duplicate value in a field restricted by a unique index. | 插入或者更新语句,与唯一索引相冲突。 |
TIMEOUT_ON_RESOURCE | ORA-00051 | You were waiting for a resource and you timed out. | 等待资源超时 |
TRANSACTION_BACKED_OUT | ORA-00061 | The remote portion of a transaction has rolled back. | 远程交易的部份交易已经回滚 |
INVALID_CURSOR | ORA-01001 | You tried to reference a cursor that does not yet exist. This may have happened because you've executed a FETCH cursor or CLOSE cursor before OPENing the cursor. | 引用一个不存在的游标,如FETCH或者是CLOSE在其OPEN之前等。 |
NOT_LOGGED_ON | ORA-01012 | You tried to execute a call to Oracle before logging in. | 在登陆ORACLE之前执行调用错误 |
LOGIN_DENIED | ORA-01017 | You tried to log into Oracle with an invalid username/password combination. | 登陆时用户名或者密码非法。 |
NO_DATA_FOUND | ORA-01403 | You tried one of the following: 1. You executed a SELECT INTO statement and no rows were returned. 2. You referenced an uninitialized row in a table. 3. You read past the end of file with the UTL_FILE package. | 执行查询无数据、引用一个末初使化的表、通过UTL_FILE包调用到尾的文件 |
TOO_MANY_ROWS | ORA-01422 | You tried to execute a SELECT INTO statement and more than one row was returned. | 采用SELECT INTO语句,但返回的记录超过了1条 |
ZERO_DIVIDE | ORA-01476 | You tried to divide a number by zero. | 0为除数 |
INVALID_NUMBER | ORA-01722 | You tried to execute an SQL statement that tried to convert a string to a number, but it was unsuccessful. | 将字符串转换成数字,但是转换失败 |
STORAGE_ERROR | ORA-06500 | You ran out of memory or memory was corrupted. | 内存不足 |
PROGRAM_ERROR | ORA-06501 | This is a generic "Contact Oracle support" message because an internal problem was encountered. | 系统自身程序错误 |
VALUE_ERROR | ORA-06502 | You tried to perform an operation and there was a error on a conversion, truncation, or invalid constraining of numeric or character data. | 在执行转换、截断、非法转换数据到文本出错 |
CURSOR_ALREADY_OPEN | ORA-06511 | You tried to open a cursor that is already open. | 打开一个已经打开的游标 |
declare
myexception exception;
begin
if 1<>2 then
raise myexception;
end if;
exception
when myexception then
/*注:raise_application_error的语法为raise_application_error(erorcd in int,erortx in varchar 2),其中erorcd的值为20001到20999*/
raise_application_error(20001,'my exception happens');
when others then
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
end
3、存储过程可能要涉及到层层调用,因此在每一次都需要写异常处理,这让程序会更健壮。
本文出自:冯立彬的博客
相关文章推荐
- Oracle异常处理—ORA-12514
- 异常断电导致ORACLE控制文件等受到破坏的处理
- Oracle 异常处理 raise_application_error sqlcode sqlerrm
- oracle 异常错误处理
- Oracle中异常处理
- ORACLE常见异常及处理
- [推荐]ORACLE PL/SQL编程之五:异常错误处理(知已知彼、百战不殆)
- 【Oracle篇】异常处理和PLSQL
- 【Oracle】第四章异常处理
- ORACLE PL/SQL 异常错误处理
- oracle/Mybatis异常处理
- Oracle PL/SQL开发基础(第二十九弹:异常处理简介)
- oracle 启动及异常处理
- Oracle:pl/sql 异常处理[转]
- Oracle异常 判断OTHERS处理程序中发生了哪个错误
- Oracle - 存储过程异常处理事务分析
- 一个利用oracle异常处理的函数
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常
- Oracle异常处理,动态游标
- Oracle异常处理—ORA-12514:监听程序当前无法识别连接描述符中请求的服务