--what is an exception--exceptions are errors that may occur during the PL/SQL run. --statement that executes the exceptionException when [Exception] when --abnormal output information. --pre-defined exceptions for OracleCase_not_found Ora-06592 --in a case statement, the When clause does not have a matching condition, and there is no else statement that fires the exception. No_data_found ORA-01403 --Select: The INTO statement does not return a record, triggering the exceptionToo_many_rows ORA-01422--Select: INTO statement returns more than one record, triggering the exceptionDup_val_on_index ORA-00001--This exception is thrown when duplicate values appear on a column that corresponds to a unique index in a tableValue_error ORA-06502--If the variable length is not sufficient, the exception is thrown when the value is assignedZero_divide ORA-01476--exception thrown when divisor is zeroStorage_Error ORA-06500--the exception is thrown by content overflow or corruptionTimeout_on_resource ORA-00051--wait for resource timeout to throw the exceptionCursor_already_open ORA-06511--open a cursor that is already open to throw the exception--non-pre-defined exception1, declares the name of an exception. 2, associating the exception name with the number of the exception. --ExampleDeclarev_tvarchar2(5); V_ttvarchar2(3); Tt_8899_exp exception;--declaring exceptionspragma exception_init (tt_8899_exp,-8899);--Exception_init (exception name, exception code)beginv_t:='1111'; Casev_t when '222' ThenDbms_output.put_line ('555'); End Case; exception whenCase_not_found ThenDbms_output.put_line ('string exceeded'); Dbms_output.put_line (SQLERRM);--Output Exception InformationDbms_output.put_line (SQLCODE);--code to output exceptions rollback; End;--Custom ExceptionsDeclarev_t Number(Ten); Tt_8899_exp exception;--declaring exceptionspragma exception_init (tt_8899_exp,-8899);--Exception_init (exception name, exception code)beginv_t:=-1; ifv_t<0 Thenraise Tt_8899_exp;--start a custom exception Tt_8899_exp End if; exception whenCase_not_found ThenDbms_output.put_line (SQLERRM);--Output Exception InformationDbms_output.put_line (SQLCODE);--code to output exceptions whenTt_8899_exp ThenDbms_output.put_line ('string exceeded'); Dbms_output.put_line (SQLERRM);--Output Exception InformationDbms_output.put_line (SQLCODE);--code to output exceptions rollback; End;
Exception handling for Oracle's Pl_sql