Raise_application_error Error Codes
Contents |
to your PL/SQL program. With many programming languages, unless you disable error checking, a run-time error such as stack overflow or division by zero stops normal processing and returns control to the raise application error oracle example operating system. With PL/SQL, a mechanism called exception handling lets you bulletproof your raise_application_error syntax program so that it can continue operating in the presence of errors. This chapter contains these topics: Overview of PL/SQL Runtime difference between raise and raise_application_error in oracle Error Handling Advantages of PL/SQL Exceptions Summary of 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 raise_application_error(-20001 Overview of PL/SQL Compile-Time Warnings Overview of PL/SQL Runtime Error Handling In PL/SQL, an error condition is called an exception. Exceptions can be internally defined (by the runtime 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
Oracle Raise
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 the enclosing block resumes with the next statement. If there is no enclosing block, control returns to the host environment. For information on managing errors when using BULK COLLECT, see "Handling FORALL Exceptions with the %BULK_EXCEPTIONS Attribute". Example 10-1 calculates a price-to-earnings ratio for a company. If the company has zero earnings, the division operation raises the predefined exception ZERO_DIVIDE, the execution of the block is interrupted, and control is transferred to the exception handlers. The optional OTHERS handler catches all exceptions that the block does not
Churchill Run-time errors arise from design faults, coding mistakes, hardware failures, and many other
Pragma Exception_init And Raise Application Error
sources. Although you cannot anticipate all possible errors, you can raise_application_error parameters plan to handle certain kinds of errors meaningful to your PL/SQL program. With many programming languages, raise application error in oracle triggers unless you disable error checking, a run-time error such as stack overflow or division by zero stops normal processing and returns control to the operating https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/errors.htm system. With PL/SQL, a mechanism called exception handling lets you "bulletproof" your program so 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 https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm 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 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) b
errors. The latter are called exceptions. Note: The language of warning and error messages depends on the NLS_LANGUAGE parameter. For information about this parameter, https://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm see Oracle Database Globalization Support Guide. Topics Compile-Time Warnings Overview of Exception Handling Internally Defined Exceptions Predefined Exceptions User-Defined Exceptions Redeclared Predefined Exceptions Raising Exceptions Explicitly Exception Propagation Unhandled Exceptions Error Code http://www.toadworld.com/platforms/oracle/b/weblog/archive/2010/07/14/raise-vs-raise-application-error and Error Message Retrieval Continuing Execution After Handling Exceptions Retrying Transactions After Handling Exceptions See Also: "Exception Handling in Triggers" "Handling FORALL Exceptions After FORALL Statement Completes" Tip: If you have problems raise application creating or running PL/SQL code, check the Oracle Database trace files. The USER_DUMP_DEST initialization parameter specifies the current location of the trace files. You can find the value of this parameter by issuing SHOW PARAMETER USER_DUMP_DEST. For more information about trace files, see Oracle Database Performance Tuning Guide. Compile-Time Warnings While compiling stored PL/SQL units, the PL/SQL compiler generates warnings for conditions that are raise application error not serious enough to cause errors and prevent compilation—for example, using a deprecated PL/SQL feature. To see warnings (and errors) generated during compilation, either query the static data dictionary view *_ERRORS (described in Oracle Database Reference) or, in the SQL*Plus environment, use the command SHOW ERRORS. The message code of a PL/SQL warning has the form PLW-nnnnn. For the message codes of all PL/SQL warnings, see Oracle Database Error Messages. Table 11-1 summarizes the categories of warnings. Table 11-1 Compile-Time Warning Categories Category Description Example SEVERE Condition might cause unexpected action or wrong results. Aliasing problems with parameters PERFORMANCE Condition might cause performance problems. Passing a VARCHAR2 value to a NUMBER column in an INSERT statement INFORMATIONAL Condition does not affect performance or correctness, but you might want to change it to make the code more maintainable. Code that can never run By setting the compilation parameter PLSQL_WARNINGS, you can: Enable and disable all warnings, one or more categories of warnings, or specific warnings Treat specific warnings as errors (so that those conditions must be corrected before you can compile the PL/SQL unit) You can set the value of PLS
SQL Server PRODUCTSDiscussion & Resources Benchmark Factory Code Tester for Oracle SharePlex SQL Navigator SQL Optimizer Spotlight Stat Toad Intelligence Central Toad Data Modeler Toad Data Point Toad Extension for Eclipse Toad for Hadoop Toad for IBM DB2 Toad for Oracle Toad for MySQL Toad for SQL Server Toad for SAP Solutions Toad MAC Edition Home » Platforms » Oracle » Oracle Blog » RAISE vs RAISE_APPLICATION_ERROR? RAISE vs RAISE_APPLICATION_ERROR? Oracle Community Join Overview Forum Blog Wiki Members Blog Options Print Comment RSS Feed Tweet Related Posts "Our" Error Codes : -20999 to -20000 by Steven Feuerstein on 3 Feb 2012 0 comments RAISE_APPLICATION_ERROR latest revision over 3 years ago by Steve Hilker Who needs comments? My code is self-documenting! AKA: Comment tersely with value-added information. by Steven Feuerstein on 28 Nov 2012 0 comments View More RAISE vs RAISE_APPLICATION_ERROR? Follow Steven Feuerstein / 7.14.2010 at 9:01pm A PL/SQL developer just sent me the following question: "I can't understand the difference between RAISE_APPLICATION_ERROR and RAISE. Why would I use one vs. the other?" Instead of answering via an email to just one developer, I thought I might share my answer with everyone. The RAISE_APPLICATION_ERROR built-in (defined in the DBMS_STANDARD package) should be used for just a single scenario: you need to communicate an application-specific error back to the user. Suppose, for example, I have a rule for the employees table that the minimum salary allowed is $100,000 (ah, wouldn't that be nice?). I want to enforce that rule through a database trigger: TRIGGER employees_minsal_tr BEFORE INSERT OR UPDATE ON employees FOR EACH ROWBEGIN IF :new.salary < 100000 THEN /* communicate error */ NULL; END IF;END; I can stop the DML from completing by issuing a RAISE statement, such as: RAISE PROGRAM_ERROR; But I would not be able to communicate back to the user what the actual problem was. If, on the other hand, I use RAISE_APPLICATION_ERROR, I can specify the error number (of little interest to my users, but a good "identifier" for support) and, more importantly, the error message, as in: TRIGGER employees_minsal_tr BEFORE INSERT OR UPDATE ON employees FOR EACH ROWBEGIN IF :new.salary < 1000000 THEN RAISE_APPLIC