Exception handling for Oracle's Pl_sql

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.