Oracle Pl Sql Get Error Message
Contents |
Churchill Run-time errors arise from design faults, coding mistakes, hardware failures, and many other sources. Although you cannot anticipate all possible sqlerrm line number errors, you can plan to handle certain kinds of errors meaningful oracle raise exception with message to your PL/SQL program. With many programming languages, unless you disable error checking, a run-time error such as oracle sqlcode list stack overflow or division by zero stops normal processing and returns control to the operating system. With PL/SQL, a mechanism called exception handling lets you "bulletproof" your program so
Functions For Error Trapping Are Contained In Which Section Of A Pl/sql Block
that it can continue operating in the presence of errors. This chapter discusses the following topics: Overview of PL/SQL Error Handling Advantages of PL/SQL Exceptions Predefined PL/SQL Exceptions Defining Your Own PL/SQL Exceptions How PL/SQL Exceptions Are Raised How PL/SQL Exceptions Propagate Reraising a PL/SQL Exception Handling Raised PL/SQL Exceptions Tips for Handling PL/SQL Errors Overview of PL/SQL oracle sql error codes Error Handling In PL/SQL, a warning or error condition is called an exception. Exceptions can be internally defined (by the run-time system) or user defined. Examples of internally defined exceptions include division by zero and out of memory. Some common internal exceptions have predefined names, such as ZERO_DIVIDE and STORAGE_ERROR. The other internal exceptions can be given names. You can define exceptions of your own in the declarative part of any PL/SQL block, subprogram, or package. For example, you might define an exception named insufficient_funds to flag overdrawn bank accounts. Unlike internal exceptions, user-defined exceptions must be given names. When an error occurs, an exception is raised. That is, normal execution stops and control transfers to the exception-handling part of your PL/SQL block or subprogram. Internal exceptions are raised implicitly (automatically) by the run-time system. User-defined exceptions must be raised explicitly by RAISE statements, which can also raise predefined exceptions. To handle raised exceptions, you write separate routines called exception handlers. After an exception handler runs, the current block stops executing and
Error Handling" in Oracle Database PL/SQL Language Reference. See the end of this chapter for TimesTen-specific considerations. The following topics are covered: Understanding exceptions Trapping exceptions Showing errors in ttIsql Differences in TimesTen: exception pl sql sqlcode handing and error behavior Understanding exceptions This section provides an overview of exceptions in
Oracle Sql Codes List
PL/SQL programming, covering the following topics: About exceptions Exception types About exceptions An exception is a PL/SQL error that is raised during
Sqlerrm Db2
program execution, either implicitly by TimesTen or explicitly by your program. Handle an exception by trapping it with a handler or propagating it to the calling environment. For example, if your SELECT statement returns multiple https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm rows, TimesTen returns an error (exception) at runtime. As the following example shows, you would see TimesTen error 8507, then the associated ORA error message. (ORA messages, originally defined for Oracle Database, are similarly implemented by TimesTen.) Command> DECLARE > v_lname VARCHAR2 (15); > BEGIN > SELECT last_name INTO v_lname > FROM employees > WHERE first_name = 'John'; > DBMS_OUTPUT.PUT_LINE ('Last name is :' || v_lname); > END; > / 8507: https://docs.oracle.com/cd/E11882_01/timesten.112/e21639/exceptions.htm ORA-01422: exact fetch returns more than requested number of rows 8507: ORA-06512: at line 4 The command failed. You can handle such exceptions in your PL/SQL block so that your program completes successfully. For example: Command> DECLARE > v_lname VARCHAR2 (15); > BEGIN > SELECT last_name INTO v_lname > FROM employees > WHERE first_name = 'John'; > DBMS_OUTPUT.PUT_LINE ('Last name is :' || v_lname); > EXCEPTION > WHEN TOO_MANY_ROWS THEN > DBMS_OUTPUT.PUT_LINE (' Your SELECT statement retrieved multiple > rows. Consider using a cursor.'); > END; > / Your SELECT statement retrieved multiple rows. Consider using a cursor. PL/SQL procedure successfully completed. Exception types There are three types of exceptions: Predefined exceptions are error conditions that are defined by PL/SQL. Non-predefined exceptions include any standard TimesTen errors. User-defined exceptions are exceptions specific to your application. In TimesTen, these three types of exceptions are used in the same way as in Oracle Database. Exception Description How to handle Predefined TimesTen error One of approximately 20 errors that occur most often in PL/SQL code You are not required to declare these exceptions. They are predefined by TimesTen. TimesTen implicitly raises the error. Non-predefined TimesTen error Any other standard TimesTen error These must be declared in the declarative section of your application. TimesTen implicitly raises
and you use the RESTRICT_REFERENCES pragma to assert its purity, you cannot specify the constraints WNPS and RNPS. Note: DBMS_UTILTY.FORMAT_ERROR_STACK is recommended over https://docs.oracle.com/cd/B28359_01/appdev.111/b28370/sqlerrm_function.htm SQLERRM, except when using the FORALL statement with its SAVE EXCEPTIONS clause. For more information, see Retrieving the Error Code and Error Message. Syntax sqlerrm_function ::= Description of the illustration sqlerrm_function.gif Keyword and Parameter Descriptions error_number An expression whose value is an Oracle Database error number. For a list of Oracle Database error numbers, see Oracle Database Error Messages. The oracle sql default error number is the one associated with the current value of SQLCODE. Like SQLCODE, SQLERRM without error_number is useful only in an exception handler. Outside an exception handler, or if the value of error_number is zero, SQLERRM returns ORA-0000. If the value of error_number is +100, SQLERRM returns ORA-01403. If the value of error_number is a oracle pl sql positive number other than +100, SQLERRM returns this message: -error_number: non-ORACLE exception If the value of error_number is a negative number whose absolute value is an Oracle Database error number, SQLERRM returns the error message associated with that error number. For example: SQL> BEGIN 2 DBMS_OUTPUT.PUT_LINE('SQLERRM(-6511): ' || TO_CHAR(SQLERRM(-6511))); 3 END; 4 / SQLERRM(-6511): ORA-06511: PL/SQL: cursor already open PL/SQL procedure successfully completed. SQL> If the value of error_number is a negative number whose absolute value is not an Oracle Database error number, SQLERRM returns this message: ORA-error_number: Message error_number not found; product=RDBMS; facility=ORA For example: SQL> BEGIN 2 DBMS_OUTPUT.PUT_LINE('SQLERRM(-50000): ' || TO_CHAR(SQLERRM(-50000))); 3 END; 4 / SQLERRM(-50000): ORA-50000: Message 50000 not found; product=RDBMS; facility=ORA PL/SQL procedure successfully completed. SQL> Examples Example 11-11, "Displaying SQLCODE and SQLERRM" Example 12-9, "Bulk Operation that Continues Despite Exceptions" Related Topics Block EXCEPTION_INIT Pragma RESTRICT_REFERENCES Pragma SQLCODE Function Retrieving the Error Code and Error Message See Also: Oracle Database Error Messages for a list of Oracle Database error messages and information about them Scripting on this page enhances content navigation, but do