华为专卖店下关:ORACLE中的异常处理

来源:百度文库 编辑:偶看新闻 时间:2024/05/02 23:52:07
1、ORALCE自带一些命名的系统异常,如下: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.
 打开一个已经打开的游标
 
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);end3、存储过程可能要涉及到层层调用,因此在每一次都需要写异常处理,这让程序会更健壮。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fenglibing/archive/2009/04/10/4059791.aspx