pragma exception_init, initialize several exceptions

Hi all

Is it possible to initialize in the pragma even more then on exception?

example:

declare

e_table_not_exists exception;

exception of _divide_in_zero e;

pragma

exception_init (e_table_not_exists,-942), (e_divide_in_zero,-1476);

.

.

Thanks in advance
Naama

No.; You must declare every exception_init in its own pragma.

ex.:

pragma exception_init (e_table_not_exists,-942);

pragma exception_init (e_divide_in_zero,-1476);

Tags: Database

Similar Questions

  • Set the error code for the exception qualified using the pragma exception_init

    Hello

    I did experiments on exception management in oracle plsql. In my experiments, I did the following anonymous plsql block.


    + < < outer_block > > +.
    declare
    + exceptions.    +
    Start
    + < < inner_block > > +.
    + State +.
    + exceptions.        +
    + start +.
    + recovery outer_block.exc +;
    + exception +.
    + What then outer_block.exc +.
    + dbms_output.put_line ("' outdoor Exception caught"); +
    + What then inner_block.exc +.
    + dbms_output.put_line ("'Inner Exception caught"); +
    + end; +
    end;


    When I run the code, I got the output "external Exception caught".

    ------------------------------------------------- PLSQL Block 2 -------------------------------------------

    I changed the code a little differently by assigning exceptions error codes.

    + < < outer_block > > +.
    declare
    + exception exc; +
    + pragma exception_init (exc,-20001); +
    Start
    + < < inner_block > > +.
    + State +.
    + exception exc; +
    + pragma exception_init (exc,-20001); +
    + start +.
    + raise_application_error (-20001, "Error"); +
    + exception +.
    + What then outer_block.exc +.
    + dbms_output.put_line ("' outdoor Exception caught"); +
    + What then inner_block.exc +.
    + dbms_output.put_line ("'Inner Exception caught"); +
    + end; +
    end;

    When I run the above code, I got the following error.

    Error on line 1
    ORA-06550: line 15, column 9:
    PLS-00484: exceptions redundant "EXC" and "EXC" must appear in the same exception handler
    ORA-06550: line 5, column 1:
    PL/SQL: Statement ignored

    Script done on line 21.

    ------------------------------------------------- PLSQL Block 3 -------------------------------------------


    To avoid this error, I changed the code again by qualifying exceptions with their block names. This time, I got a different error.

    + < < outer_block > > +.
    declare
    + exception exc; +
    + pragma exception_init (outer_block.exc,-20001); +
    Start
    + < < inner_block > > +.
    + State +.
    + exception exc; +
    + pragma exception_init (inner_block.exc,-20001); +
    + start +.
    + raise_application_error (-20001, "Error"); +
    + exception +.
    + What then outer_block.exc +.
    + dbms_output.put_line ("' outdoor Exception caught"); +
    + What then inner_block.exc +.
    + dbms_output.put_line ("'Inner Exception caught"); +
    + end; +
    end;


    Error on line 1
    ORA-06550: line 4, column 38:
    PLS-00103: encountered the symbol ". «» When expecting one of the following values:

    ), = >
    The symbol"were replaced by". "to continue.
    ORA-06550: line 9, column 42:
    PLS-00103: encountered the symbol ". «» When expecting one of the following values:

    ), = >
    The symbol"were replaced by". "to continue.



    Question:
    Pourraient several exceptions with the same name of the exception defined in the set of nested blocks plsql assign error codes using the pragma EXCEPTION_INIT? If there are errors in the PLSQL 2 blocks and 3, please suggest.
    If the same thing could be accomplished by other methods, please explain.

    The problem in your code block 2 is that you have not only used the same name of the exception, but you have assigned them with the same exception code. If the code is different so it will work...

    SQL> set serverout on
    SQL> ed
    Wrote file afiedt.buf
    
      1  <>
      2  declare
      3      exc exception;
      4      pragma exception_init(exc,-20001);
      5  begin
      6      <>
      7      declare
      8          exc exception;
      9          pragma exception_init(exc,-20002);
     10      begin
     11          raise_application_error(-20002,'Error raised');
     12      exception
     13          when outer_block.exc then
     14              dbms_output.put_line('outer Exception caught ' );
     15          when inner_block.exc then
     16              dbms_output.put_line('Inner Exception caught ' );
     17      end;
     18* end;
    SQL> /
    Inner Exception caught
    
    PL/SQL procedure successfully completed.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  <>
      2  declare
      3      exc exception;
      4      pragma exception_init(exc,-20001);
      5  begin
      6      <>
      7      declare
      8          exc exception;
      9          pragma exception_init(exc,-20002);
     10      begin
     11          raise_application_error(-20001,'Error raised');
     12      exception
     13          when outer_block.exc then
     14              dbms_output.put_line('outer Exception caught ' );
     15          when inner_block.exc then
     16              dbms_output.put_line('Inner Exception caught ' );
     17      end;
     18* end;
    SQL> /
    outer Exception caught
    
    PL/SQL procedure successfully completed.
    
  • SEVERE: Exception initialization 'oracle.dbtools.crest.fcp.DataModelerAddin' extension ' Oracle SQL Developer Data Modeling

    After some testing today with a new installation and plugin subversion in the latest edition of data Modeler this error happens with every start of the tool.

    Have removed and unzipped the installation once again without changing the error.

    After that, I started with another user on my computer, it the error does not occur.

    Is there a system folder to remove the configuration of my personal like jdeveloper and sql developer?

    I lose the most important features, for example. have no browser and cannot open a design.

    Here is the full error stack:

    29 may 2015 22:17:40 oracle.ideimpl.extension.AddinManagerImpl

    SEVERE: Exception initialization 'oracle.dbtools.crest.fcp.DataModelerAddin' extension ' Oracle SQL Developer Data Modeling

    java.lang.NullPointerException

    at oracle.dbtools.crest.swingui.editor.UDPLibrariesPersistence.load(UDPLibrariesPersistence.java:220)

    at oracle.dbtools.crest.model.design.DesignSet.createElement(DesignSet.java:56)

    at oracle.dbtools.crest.swingui.ApplicationView.addDesign(ApplicationView.java:2497)

    to oracle.dbtools.crest.swingui.ApplicationView. < init > (ApplicationView.java:435)

    to oracle.dbtools.crest.swingui.ApplicationView. < init > (ApplicationView.java:389)

    at oracle.dbtools.crest.swingui.ApplicationView.getInstance(ApplicationView.java:2258)

    at oracle.dbtools.crest.fcp.DataModelerAddin.initialize(DataModelerAddin.java:553)

    at oracle.ideimpl.extension.AddinManagerImpl.initializeAddin(AddinManagerImpl.java:496)

    at oracle.ideimpl.extension.AddinManagerImpl.initializeAddin(AddinManagerImpl.java:483)

    at oracle.ideimpl.extension.AddinManagerImpl.initializeAddins(AddinManagerImpl.java:299)

    at oracle.ideimpl.extension.AddinManagerImpl.initProductAndUserAddins(AddinManagerImpl.java:160)

    at oracle.ideimpl.extension.AddinManagerImpl.initProductAndUserAddins(AddinManagerImpl.java:143)

    at oracle.ide.IdeCore.initProductAndUserAddinsAndActionRegistry(IdeCore.java:2294)

    at oracle.ide.IdeCore.startupImpl(IdeCore.java:1817)

    at oracle.ide.Ide.startup(Ide.java:772)

    at oracle.ide.osgi.Activator.start(Activator.java:209)

    to org.eclipse.osgi.framework.internal.core.BundleContextImpl$ 1.run(BundleContextImpl.java:711)

    at java.security.AccessController.doPrivileged (Native Method)

    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)

    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)

    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)

    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)

    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)

    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)

    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)

    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)

    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)

    at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalStart(EquinoxLauncher.java:271)

    at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.start(EquinoxLauncher.java:241)

    at org.eclipse.osgi.launch.Equinox.start(Equinox.java:258)

    at org.netbeans.core.netigso.Netigso.start(Netigso.java:191)

    at org.netbeans.NetigsoHandle.startFramework(NetigsoHandle.java:209)

    at org.netbeans.ModuleManager.enable(ModuleManager.java:1352)

    at org.netbeans.ModuleManager.enable(ModuleManager.java:1156)

    at org.netbeans.core.startup.ModuleList.installNew (ModuleList.java:340)

    at org.netbeans.core.startup.ModuleList.trigger (ModuleList.java:276)

    at org.netbeans.core.startup.ModuleSystem.restore (ModuleSystem.java:301)

    at org.netbeans.core.startup.Main.getModuleSystem (Main.java:181)

    at org.netbeans.core.startup.Main.getModuleSystem (Main.java:150)

    at org.netbeans.core.startup.Main.start (Main.java:307)

    at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:123)

    at java.lang.Thread.run(Thread.java:745)

    Hi Torsten,

    Thanks for reporting the problem. I logged a bug.

    You can view together as "list of system types" directory to "preference > Data Modeler"-probably no longer exists. I guess that the setting for this directory is empty when you start SQL Dev as a different user.

    Philippe

  • PRAGMA EXCEPTION_INIT works not as you wish

    Hi all

    I created a procedure where in I am trying to generate an error message saying "Table is missing from the database" when an id (2617804) is passed. To ensure that there is no such thing as the name of the table, then instead of the error is handled by OTHERS WHEN I want to be manipulated by my own error message and however which is a failure as well as control passes to 'OTHERS'.

    Can someone help me?

    Here is the code:

    Package:

    CREATE OR REPLACE PACKAGE CTNAPP.SANDEEP_XMLXTRACT IS
    
      /*****************************************************************************
      * Global Public Variables for error handling
      *****************************************************************************/
      g_vProgramName VARCHAR2(30):= 'CNZ017';
      g_vPackageName VARCHAR2(30):= 'CTN_PUB_CNTL_EXTRACT_PUBLISH';
      g_vProcedureName VARCHAR2(30);
      g_vTableName VARCHAR2(30);
      g_nSqlCd NUMBER;
      g_vErrorMessage VARCHAR2(2000); 
       
      /*****************************************************************************
      * Global Public Variables
      *****************************************************************************/  
      --Type declarations for GetCtnData procedure
      TYPE g_tVCArrayTyp IS 
      TABLE OF VARCHAR2(32767)
      INDEX BY BINARY_INTEGER;
      g_tVarcharArray g_tVCArrayTyp;
    
      TYPE g_tTblIDsTyp IS 
      TABLE OF NUMBER
      INDEX BY BINARY_INTEGER;
    
      PROCEDURE GetCtnData(p_nInCtnPubCntlID IN ctn_pub_cntl.ctn_pub_cntl_id%TYPE
      , p_tOutVarCharArray OUT g_tVCArrayTyp
      , pCount OUT NUMBER);
    
    
    
    
    
    
    

    Package body:

    CREATE OR REPLACE PACKAGE BODY CTNAPP.SANDEEP_XMLXTRACT IS
    
      -- Local Variables
      XMLctx DBMS_XMLGEN.CTXHANDLE;
      XMLdoc xmldom.DOMDocument;
      root_node xmldom.DOMNode;
      child_node xmldom.DOMNode;
      child_elmt xmldom.DOMElement;
      leaf_node xmldom.DOMNode;
      elmt_value xmldom.DOMText;
    
      vStrSqlQuery VARCHAR2(32767);
      nKiloByteLimit NUMBER(6) := 30000;
      dCurrentDate TIMESTAMP := SYSTIMESTAMP;
    
    -- Private Procedures 
      /************************************************************************
      *NAME : BuildCPRHeader
      *TYPE : FUNCTION
      *INPUT : 
      *OUTPUT : 
      *DESCRIPTION :  
      *  
      *************************************************************************/
      FUNCTION BuildCPRHeader RETURN VARCHAR2 IS
      vpublishHdr VARCHAR2(2000) := NULL;
      BEGIN
    
      XMLdoc := xmldom.newdomdocument;
      root_node := xmldom.makeNode(XMLdoc);
    
      child_elmt := xmldom.createElement(XMLdoc, 'PUBLISH_HEADER');
      child_node := xmldom.appendChild (root_node, xmldom.makeNode (child_elmt));
       
      child_elmt := xmldom.createElement (XMLdoc, 'SOURCE_APLCTN_ID');
      elmt_value := xmldom.createTextNode (XMLdoc, 'CTN');
      leaf_node := xmldom.appendChild (child_node, xmldom.makeNode (child_elmt));
      leaf_node := xmldom.appendChild (leaf_node, xmldom.makeNode (elmt_value));
    
      child_elmt := xmldom.createElement (XMLdoc, 'SOURCE_PRGRM_ID');
      elmt_value := xmldom.createTextNode (XMLdoc, g_vProgramName);
      leaf_node := xmldom.appendChild (child_node, xmldom.makeNode (child_elmt));
      leaf_node := xmldom.appendChild (leaf_node, xmldom.makeNode (elmt_value));
    
      child_elmt := xmldom.createElement (XMLdoc, 'SOURCE_CMPNT_ID');
      elmt_value := xmldom.createTextNode (XMLdoc, g_vPackageName);
      leaf_node := xmldom.appendChild (child_node, xmldom.makeNode (child_elmt));
      leaf_node := xmldom.appendChild (leaf_node, xmldom.makeNode (elmt_value));
    
      child_elmt := xmldom.createElement (XMLdoc, 'PUBLISH_TMS');
      elmt_value := xmldom.createTextNode (XMLdoc, TO_CHAR(dCurrentDate, 'YYYY-MM-DD HH24:MI:SS'));
      leaf_node := xmldom.appendChild (child_node, xmldom.makeNode (child_elmt));
      leaf_node := xmldom.appendChild (leaf_node, xmldom.makeNode (elmt_value));
    
      xmldom.writetobuffer(XMLdoc, vPublishHdr);
    
      RETURN vPublishHdr;
       
      END BuildCPRHeader;
    
    
    PROCEDURE GetCtnData(p_nInCtnPubCntlID IN ctn_pub_cntl.ctn_pub_cntl_id%TYPE, 
      p_tOutVarCharArray OUT g_tVCArrayTyp, 
      pCount OUT NUMBER)
      IS
      vTblName ctn_pub_cntl.table_name%TYPE;
      vLastPubTms ctn_pub_cntl.last_pub_tms%TYPE;
      l_clob CLOB;
      nCount PLS_INTEGER;
      nLength PLS_INTEGER;
      noffset PLS_INTEGER;
       
      table_not_found EXCEPTION;
      PRAGMA EXCEPTION_INIT(table_not_found, -00942);
       
      BEGIN
       
      g_vProcedureName:='GetCtnData';
       
      SELECT table_name, last_pub_tms
      INTO vTblName, vLastPubTms
      FROM CTN_PUB_CNTL
      WHERE ctn_pub_cntl_id = p_nInCtnPubCntlID;
       
      IF sql%ROWCOUNT = 0 THEN
      RAISE no_data_found;
      END IF;
    
      DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','''YYYY:MM:DD HH24:MI:SS''');
      vStrSqlQuery := 'SELECT * FROM ' || vTblName
      || ' WHERE record_update_tms <= TO_DATE(''' || TO_CHAR(vLastPubTms, 'MM/DD/YYYY HH24:MI:SS') || ''', ''MM/DD/YYYY HH24:MI:SS'')'
      || ' AND rownum < 2'
      || ' ORDER BY record_update_tms'
      ;
    
      XMLctx := DBMS_XMLGEN.NEWCONTEXT(vStrSqlQuery);
      DBMS_XMLGEN.SETNULLHANDLING(XMLctx, 2);
      DBMS_XMLGEN.SETROWSETTAG(XMLctx, vTblName);
      l_clob := DBMS_XMLGEN.GETXML(XMLctx);
      l_clob := REPLACE(l_clob, '<?xml version="1.0"?>', '');
    
      l_clob := '<?xml version="1.0"?>' || CHR(13) || CHR(10)
      || '<PUBLISH> ' || CHR(13) || CHR(10)
      || BuildCPRHeader
      || '<PUBLISH_BODY> '
      || l_clob
      || '</PUBLISH_BODY> ' || CHR(13) || CHR(10)
      || '</PUBLISH>';
    
    -- l_clob := '<' || vTblName || '/>';
    
      nLength := DBMS_LOB.getlength(l_clob);
      nCount := CEIL(nLength / nKiloByteLimit);
    
      noffset := 1;
      IF (nCount > 0) THEN
      FOR i in 1 .. nCount LOOP
      p_tOutVarCharArray(i) := DBMS_LOB.SUBSTR(l_clob, nKiloByteLimit, noffset);
      noffset := noffset + nKiloByteLimit;
      dbms_output.put_line(p_tOutVarCharArray(i));
      END LOOP;
      END IF;
    
      pCount := nCount;
       
      EXCEPTION 
      WHEN table_not_found THEN
      RAISE_APPLICATION_ERROR(-20001,'Table is missing from the database');  
       
      WHEN no_data_found THEN
      CTNAPP_COMMON.write_log(g_vPackageName, g_vProcedureName, NULL,'INFORMATIONAL','XMLTOSAP');
       
      --WHEN too_many_rows THEN
      -- CTNAPP_COMMON.write_log(g_vPackageName, g_vProcedureName, NULL,'FATAL','XMLTOSAP');
       
      WHEN others THEN
      CTNAPP_COMMON.write_log(g_vPackageName, g_vProcedureName,NULL, 'ERROR','XMLTOSAP');
       
      END GetCtnData;
    

    and now, to call my own procedure:


    CREATE OR REPLACE PROCEDURE CTNAPP.SANDEEP_TEST_LAMXML
    IS
    
    l_tOutVarCharArray SANDEEP_XMLXTRACT.g_tVCArrayTyp;
    
    nCount NUMBER(5);
    
    BEGIN  
    END;
    /
    
    
    
     SANDEEP_XMLXTRACT.GetCtnData(2617804, l_tOutVarCharArray,nCount);
    
    
    
    


    When in 2617804 is an id that has a table name called 'sandeep' and this 'sandeep' is passed dynamically (such as there might be a table of someother name in the future) in the variable vStrSqlQuery.

    Can anyone let me know where I am going wrong. I tried a small prototype with PRAGMA EXCEPTION_INIT (which worked successfully) before generating the error for the production program manager.

    @Solomon and Jarkko: thanks for explaining things in detail and why this code is redundant. I'll remove it. As for the original question, it is now fixed. I spent just "EXECUTE IMMEDIATE vStrSqlQuery;" after "vStrSqlQuery" and that fixed the issue. He went immediately to the error handler I wanted him (WHEN table_not_found THEN) as opposed to "When OTHERS" Finally the issue is fixed. Thanks a lot for everyone taking the time. Very much appreciated.

  • Pragma EXCEPTION_INIT or RAISE_APPLICATION_ERROR - that is good practice

    Hello

    I have came across a point where I need suggestion and views on error handling. However I use above all error handler.
    But in case the base unit (inside) / program that calls that one would be preferable to use the PRAGMA EXCEPTION_INIT or directly use RAISE_APPLICATION_ERROR.

    Here's the example I've tried

    SQL> DECLARE
      2  L_CNT NUMBER;
      3  NO_DATA_FND EXCEPTION;
      4  PRAGMA EXCEPTION_INIT(NO_DATA_FND,100);
      5  BEGIN
      6   SELECT 1 INTO  L_CNT
      7       FROM DUAL WHERE 1=2;
      8  EXCEPTION
      9      WHEN NO_DATA_FND  THEN
     10      raise NO_DATA_FND  ;
     11  End;
     12  /
    DECLARE
    *
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 10
    ORA-01403: no data found
    

    Or is better

    SQL> DECLARE
      2  L_CNT NUMBER;
      3  BEGIN
      4   SELECT 1 INTO  L_CNT
      5       FROM DUAL WHERE 1=2;
      6  EXCEPTION
      7      WHEN NO_DATA_FOUND THEN
      8      RAISE_APPLICATION_ERROR(-20001,'OR is this good way of handling');
      9  End;
     10  /
    DECLARE
    *
    ERROR at line 1:
    ORA-20001: OR is this good way of handling
    ORA-06512: at line 8
    

    No, it's not the same.

    Let's say you had a PL/SQL code you want to process the cases where you get an error ORA-01234 (for example), and you want to write an exception handler for it. You could use exception_init for card ORA-01234 an exception called MY_EXCEPTION and then use "when MY_EXCEPTION" in your exception handler. It has NOTHING to do with the throwing of an exception. You can also use this name to throw the exception directly

    raise_application_error throws an exception with a specific number and text associated with it. The error number must be within a specified range (-20000 29999 if memory serves).

  • Pragma Exception_INIT-doubt

    Hi all

    Why we use Pragma Exception_INIT what is the purpose?
    Declare     
          e_MissingNull EXCEPTION;
         PRAGMA EXCEPTION_INIT(e_MissingNull, -1400);
    BEGIN
         INSERT INTO Employees (employee_id) VALUES (NULL);
    EXCEPTION
         WHEN e_MissingNull then
            DBMS_OUTPUT.put_line('ORA-1400 occurred');
    END;
    When I give the code above I
    PL/SQL procedure successfully completed. ORA-1400 has occurred

    The same code when I try to give the error message is ORA-1500 took place
    I get
    ORA-01400: cannot insert NULL into ("XXI". "'"' EMPLOYEES'."" EMPLOYEE_ID')
    ORA-06512: at line 6
    Why is it happening?

    And when I use to try to get the error messgae to display not valid instead of Zero_divide
    Declare    
           I Number; 
          e_sample EXCEPTION;
         PRAGMA EXCEPTION_INIT(e_sample, -5737);
    BEGIN
         select 1/0 Into I From Dual ; -- I know Zero_Divide Error i thought the changing this error in my style 
    EXCEPTION
         WHEN e_smple then
            DBMS_OUTPUT.put_line('ORA-5737 Not valid');
    END;
    But the result is
    ORA-01476: divisor is equal to zero

    Please let me know the purpose and the use of Pragma Exception_INIT

    I thank in advance
    Suresh

    Please take a read of {: identifier of the thread = 697262} for a better understanding of the management of exceptions.

    Looks like you are trying to do parts of more advanced pragma of handling exceptions before you even understand the basics.

  • initialize several mice

    Is it possible to initialize several mouse?  I am running an application that allows to separate mouse control separate cursors on the same pc, called entered plural.

    I would like to be able to track the position of the two mice, but I am only able to follow my mouse system.

    As far as I know, LV has no way to distinguish the mouse, as the operating system that abstracts away.

    One option could be to use the library of the queue Message of Windows to see if the service WMs include an ID of mouse as part of a move to the mouse message.

    Another would be to install the device as a USB RAW device and read the data yourself. You can see some details about it here - http://forums.ni.com/t5/LabVIEW/Nugget-1-of-n-GEtting-started-with-USB-communication-via-VISA/m-p/74...  and it should be also one or two sons follow-up, so do a search for "USB nugget" If you want to read them. Personally, I have not done anything like that, but I understand that it should work.

  • Understanding Pragma Init Exception and others then exception...

    Hi gurus,

    I understand that using the pragma init exception, allows you to associate the user with valid error plsql code defined error message.

    But can not be managed using so that other then an exception? Using sqlerrm and sqlerrcode, we can display error messages and log them.

    Could you please help me understand this?

    Thank you

    I understand that using the pragma init exception, allows you to associate the user with valid error plsql code defined error message.

    Correct - the doc of the PL/SQL language

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/exceptioninit_pragma.htm

    The EXCEPTION_INIT pragma associates a name of the exception defined by the user with an error code.

    . . .

    Error_code

    Error code for being associated to exception . error_code may be 100 (digital code for "no data found" this 'function SQLCODE' return) or any negative integer greater than-10000000 except-1403 (another digital code for "no data found").

    This doc link also has examples of using the pragma

    But can not be managed using so that other then an exception? Using sqlerrm and sqlerrcode, we can display error messages and log them.

    Could you please help me understand this?

    First – understand this: If you do not go to 'manage' exception you shouldn't use an exception handler initially. Let the exception propagate up to the appellant.

    Second - you should NOT use THEN than OTHERS as a replacement for an appropriate exception handler.

    Which of them do you find easier to read, understand and maintain?

    1-60

    2 DEADLOCK_DETECTED

    Don't you think that ANYONE, no matter how expert, recalled all of the Oracle error codes? The names are much easier to understand than a number.

    The pragma is used so that you can explicitly declare an exception handler for one of the unnamed Oracle error codes.

    New - see the documentation

    http://docs.Oracle.com/CD/B19306_01/AppDev.102/b14261/errors.htm#BABGIIBI

    To handle error conditions (generally ORA- messages) who do not have predefined name, you must use the OTHERS Manager or the pragma EXCEPTION_INIT .

    A pragma is a compiler directive which is processed at the time of compilation, not running.

    In PL/SQL, the pragma EXCEPTION_INIT tells the compiler to associate a name of the exception to an Oracle error number. Allows you to make reference to any inner exception by name, write a specific handler for it. When you see an error in the cell, or sequence of error messages, one on top is that you can intercept and manage.

    The pragma is used to catch an exception that "should" occur in the execution. Then, this exception can be handled. If it is NOT handled (for example if you just connect it) the exception handler should re - raise the exception rather than just swallowing it.

  • Can ' transaction autonomous pragma ' called from exception block?

    CREATE OR REPLACE TRIGGER TRIG_EMP
    AFTER UPDATE
    ON EMP
    FOR EACH LINE

    DECLARE

    NUMBER OF THE CNT: = 0;

    BEGIN

    UPDATE EMP_bkp
    SET COMM = 999
    WHERE ENAME = 'SMITH ';.

    COMMIT; -It will generate the error that commit the cnt b use inside the trigger then wil code exception sommunications

    exception
    while others then
    declare
    PRAGMA AUTONOMOUS_TRANSACTION;
    Start
    commit;
    end;
    END;


    Why code gives error? cant I put PRAGMA AUTONOMOUS_TRANSACTION block of exception, even if I have the rolls in declare... begin... end of block.
    Could be considered to bear, but I m in delema why we cnt pragma 'use', in the exception block when an error themselves in code.as can call any proc, func via exception block then why don't we call pragma?

    A pragma shall apply to a set routine:
    -The anonymous PL/SQL blocks higher level (not nested)
    -Local, autonomous and packaged functions and procedures
    -A SQL object type methods
    -Database triggers

    But, even if you set a pragma autonomous_transaction in the exceptions, these commit will not commit the changes maded in the body of the trigger (because the idea of a stand-alone transaction, is independent).

    Perhaps (I'm not sure) you can try to trick Oracle write a function that do the validation.

    In any case, what you trying to do? There may be another way to achieve your goals

    I hope this helps.

    Kind regards
    Alfonso Vicente
    http / / www.logos.com.uy/el_blog_de_alfonso

  • Defined by the user exception handling

    Hello

    version Oracle 11.1.0.7

    Question 1:
    I just want to know what is the difference between the methods for using user-defined exceptions.

    Method 1: don't need initialization exception
    create or replace procedure p1
    as
    exc_p1 exception;
    begin
     do something .... 
     -- fails
     Raise exc_p1;
     exception when exc_p1 then
     raise;
     end;
     
    Method 2: use initialization exception
     create or replace procedure p2
     as
    exc_p2 exception;
    prgma exception_init(exc_p2,-20999);
    begin 
    p1;
    exception
    when exc_p2 then 
    raise;
    end;
    Question2

    Please let me know when and where to use these user-defined functions and I read the comments of Tom kyte on the use then than others, then raise or raise_application_error
    exception management. Rather than use the raise or raise_application_error can I use "dbms_output.put_line (dbms_utility.format_error_backtrace); dbms_output.put_line (dbms_utility.format_error_stack)) 'or can I do the exceptions as handler below.
    " when others then 
    raise_application_error(-20001,'error in p1  '||dbms_utility.format_error_backtrace ||dbms_utility.format_error_stack); " 
    Thank you
    Mike

    Mike wrote:
    Hello

    version Oracle 11.1.0.7

    Question 1:
    I just want to know what is the difference between the methods for using user-defined exceptions.

    Method 1: don't need initialization exception

    create or replace procedure p1
    as
    exc_p1 exception;
    begin
    do something ....
    -- fails
    Raise exc_p1;
    exception when exc_p1 then
    raise;
    end;
    

    Method 2: use initialization exception

    create or replace procedure p2
    as
    exc_p2 exception;
    prgma exception_init(exc_p2,-20999);
    begin
    p1;
    exception
    when exc_p2 then
    raise;
    end;
    

    The first method is used when you plan to raise user-defined errors by using the name, and user-defined errors are raised in the procedure you capture them.

    The second method is used when you want to capture a specific error number, it's an error specific oracle (one that has not already been appointed) or a user defined error. In your example procedures, if we show what exceptions occur by putting in the debugging...

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace procedure p1 as
      2    exc_p1 exception;
      3  begin
      4    Raise exc_p1;
      5  exception when exc_p1 then
      6    dbms_output.put_line('P1:exc_p1');
      7    raise;
      8* end;
    SQL> /
    
    Procedure created.
    
    SQL>
    SQL> create or replace procedure p2 as
      2    exc_p2 exception;
      3    pragma exception_init(exc_p2,-20999);
      4  begin
      5    p1;
      6  exception
      7    when exc_p2 then
      8      dbms_output.put_line('P2:exc_p2');
      9      raise;
     10    when others then
     11      dbms_output.put_line('Other exception');
     12      raise;
     13  end;
     14  /
    
    Procedure created.
    
    SQL> set serverout on
    SQL> exec p2;
    P1:exc_p1
    Other exception
    BEGIN p2; END;
    
    *
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SCOTT.P2", line 12
    ORA-06512: at line 1
    

    ... we can see that the captured P1 procedure an exception defined by the user by his name, but procedure P2 could only recognize as being a mistake 'OTHERS '.

    But if P1 were to raise a specific error number...

    SQL> create or replace procedure p1 as
      2    exc_p1 exception;
      3  begin
      4    Raise exc_p1;
      5  exception when exc_p1 then
      6    dbms_output.put_line('P1:exc_p1');
      7    raise_application_error(-20999,'Procudure 1 error raised',true);
      8  end;
      9  /
    
    Procedure created.
    
    SQL> exec p2;
    P1:exc_p1
    P2:exc_p2
    BEGIN p2; END;
    
    *
    ERROR at line 1:
    ORA-20999: Procudure 1 error raised
    ORA-06512: at "SCOTT.P1", line 7
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SCOTT.P2", line 9
    ORA-06512: at line 1
    
    SQL>
    

    ... then because P2 is looking for this under his own name of exp_p2 error number, he seized the exception thrown by P1 as is exp_p2 exception.

    Now, just to complete the example...

    SQL> create or replace procedure p1 as
      2    exc_p1 exception;
      3    pragma exception_init(exc_p1,-20999);
      4  begin
      5    Raise exc_p1;
      6  exception when exc_p1 then
      7    dbms_output.put_line('P1:exc_p1');
      8    raise;
      9  end;
     10  /
    
    Procedure created.
    
    SQL> exec p2;
    P1:exc_p1
    P2:exc_p2
    BEGIN p2; END;
    
    *
    ERROR at line 1:
    ORA-20999:
    ORA-06512: at "SCOTT.P2", line 9
    ORA-06512: at line 1
    

    ... P1 has now associated with error number 20999 is exc_p1 exception, when he simply raises this exception is triggered 20999 error number. P2 is unable to capture under the name of exc_p1 because this exception name does exist in the process of P1, but because P2 seeks 20999 under his own name of exc_p2 exception, it manages to capture him.

    So, to summarize, the name of the exception without the pragma is allowed to handle exceptions as part of the same name, but if you need capture outside the scope, you use the pragma to assign a number to it-specific exception.

    Question2

    Please let me know when and where to use these user-defined functions and I read the comments of Tom kyte on the use then than others, then raise or raise_application_error

    User-defined exceptions are used mainly to treat logic errors. The key is the word "handful." If you can handle an exception (i.e. to do something) you should capture it and do what needs doing. If you can't handle it then, you have to trigger it.
    Using a then "than others' exception should be a last resort. In general, you only manage exceptions that you plan to arrive. One then "than others' captures all exceptions that have not already been dealt with. If you have an exception "while others" and you do not throw the exception upward once again, then effectively hide you any errors to get noticed (errors are still happening, but you are not aware of them except for the fact that your "code does not work" or "data is not correct"). The only time you would really use one then "than others' exception would be if you need to connect all the errors in a table, but then after the cut, which should continue to be the exception to the calling code.

    exception management. Rather than use the raise or raise_application_error can I use "dbms_output.put_line (dbms_utility.format_error_backtrace); dbms_output.put_line (dbms_utility.format_error_stack)) 'or can I do the exceptions as handler below.

    " when others then
    raise_application_error(-20001,'error in p1  '||dbms_utility.format_error_backtrace ||dbms_utility.format_error_stack); " 
    

    You should not use dbms_output.put_line, except for the purpose of debugging. To use that assumes that the output of the server is catches or displayed, which, if it is a backend process, it won't. The correct way to error log is a table, or at worst a file on the server.

    If you need generate an application error and you want to keep the stack error, you just need the third parameter set to TRUE.

    raise_application_error({errornumber},{message},true);
    
  • Why I'm not able to associate the user defined exception with ORA-01403 error code

    why I am not able to

    Associate a user defed exception with ORA-01403 error code?

    declare
     myException Exception;
     pragma exception_init(myException ,-1403);
    
     begin
     raise myException ;
    Exception
    when myException  then
     dbms_output.put_line('raised due to myException ');
     end;
    /
    

    exception of ABC;

    *

    ERROR on line 2:

    ORA-06550: line 2, column 4:

    PLS-00701: ORACLE error-1403 of PRAGMA EXCEPTION_INIT illegal number

    ORA-1403 is an outgoing BOF NO_DATA_FOUND exception. And we used to NO_DATA_FOUND in pragma exception_init + 100.

    Thus, instead of the you can used this different exception code which is not associated with any exception.

    For example:

    declare

    Exception myException;

    pragma exception_init (myException,-7856);

    Start

    raise myException;

    Exception

    When myException then

    dbms_output.put_line ('high due myException');

    end;

  • My OTHER works of exception handler, but NO_DATA_FOUND and ZERO_DIVIDE does not work.

    My employees table doesn't have a record with employe_id of 250.I identified a user defined NO_DATA_FOUND but without any result. The handler to E exceptions. A. is executed instead.

    DECLARE

    v_employee_id employees.employee_id%TYPE;

    v_salary employees.salary%TYPE;

    v_job_id employees.job_id%TYPE;

    Sum_Salary copy_employees.salary%TYPE;

    number of v_num;

    NO_DATA_FOUND EXCEPTION;

    pragma exception_init (no_data_found,-00251);

    BEGIN

    SELECT the salary, job_id INTO v_salary, v_job_id

    Employees

    WHERE employee_id = 250;

    v_num:=(100/0);

    EXCEPTION

    WHEN no_data_found THEN

    DBMS_OUTPUT. Put_line (' you crazy!) ');

    WHEN standard.zero_divide THEN

    DBMS_OUTPUT. Put_line (' how you can divide by zero?) ');

    WHILE others THEN

    DBMS_OUTPUT. Put_line (' Hey, support technique contact!');

    END;

    I've run it: -.

    SQL > DECLARE

    v_employee_id 2 employees.employee_id%TYPE;

    3 v_salary employees.salary%TYPE;

    4 v_job_id employees.job_id%TYPE;

    5 sum_salary copy_employees.salary%TYPE;

    Number 6 v_num;

    7 no_data_found EXCEPTION;

    pragma 8 exception_init (no_data_found,-00251);

    BEGIN 9

    10. SELECT salary, job_id INTO v_salary, v_job_id

    11 used FROM

    12. WHERE the employee_id = 250;

    13 v_num:=(100/0);

    14 EXCEPTION

    15. WHEN no_data_found THEN

    16 DBMS_OUTPUT. Put_line (' you crazy!) ');

    17. WHEN standard.zero_divide THEN

    18 DBMS_OUTPUT. Put_line (' how you can divide by zero?) ');

    19 THEN than others THEN

    20 DBMS_OUTPUT. Put_line (' Hey, support technique contact!');

    21 END;

    22.

    Hey, contact technical support.

    PL/SQL procedure successfully completed.

    What do you see when you try this... you don't need pragma statement.

    DECLARE
    v_employee_id employees.employee_id%TYPE;
    v_salary employees.salary%TYPE;
    v_job_id employees.job_id%TYPE;
    Sum_Salary copy_employees.salary%TYPE;
    v_num NUMBER;
    BEGIN
    SOME treatments, job_id
    IN v_salary, v_job_id
    Employees
    WHERE employee_id = 250;

    v_num: = (100 / 0);
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    DBMS_OUTPUT. Put_line (' you crazy!) ');
    WHEN ZERO_DIVIDE
    THEN
    DBMS_OUTPUT. Put_line (' how you can divide by zero?) ');
    WHILE OTHERS
    THEN
    DBMS_OUTPUT. Put_line ("Hey, support technique contact!");
    END;
    /

  • Help with the exception of Pl/SQL 'ora-3150 end of file on the communication channel.

    Hello.

    The code attached to this post opens a slider that load of 99 dblinks from different remote databases of different version.

    He captures the information from these databases and stores them locally on a central database (11.2.0.4.0 version) on different tables.

    The problem I have is that when a database is deleted, the dblink to this database show me the error 'ora-3150 end of file on communication channel' and that's right.

    But he's not going trough the exception that I created, the cursor is closed and does not continue with the cycle.

    The exception I created insert data on DBMONITOR error. DBMONITOR_LOG_ERROR_TABLE in order to catch the error (you'll be able to see all the code on the attachment)

    It's the exception:

    exception

    while others then

    INSERT IN DBMONITOR. DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info, FECHA_ERROR, TIPO_PROCEDURE) VALUES (var, SUBSTR (DBMS_UTILITY. (FORMAT_ERROR_STACK, 1, 200), "CONNECTION ERROR", SYSDATE, 'CAPACITY');

    commit;

    end;

    Could help me please on how could intercept this exception?

    Thank you.

    Juan.

    You might have a problem with your connection or mishandling. The end of the file ora-3150, on channel of communication error means that there is a connection, but this link was broken somehow.

    If a database is not reachable, you should get other types of errors.

    For example judgment of the Kingdom or tns - memory could not resolve alias or simliar things.

    Here is a list of typical mistakes I have check and manage when accessing remote databases.

      e_db_link_broken EXCEPTION;  --ORA-02019 connection description for remote database not found
      PRAGMA EXCEPTION_INIT (e_db_link_broken, -02019);
      e_oracle_not_available EXCEPTION;  --ORA-01034 ORACLE not available
      PRAGMA EXCEPTION_INIT (e_oracle_not_available, -01034);
      e_oracle_down EXCEPTION;  --ORA-27101: shared memory realm does not exist
      PRAGMA EXCEPTION_INIT (e_oracle_down, -27101);
      e_no_listener EXCEPTION;  --ORA-12541: TNS:no listener
      PRAGMA EXCEPTION_INIT (e_no_listener, -12541);
      e_no_service EXCEPTION;  --ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
      PRAGMA EXCEPTION_INIT (e_no_service, -12514);
      e_timeout EXCEPTION;  --ORA-12170: TNS:Connect timeout occurred
      PRAGMA EXCEPTION_INIT (e_timeout, -12170);
    

    If you have a long open session and fail to close the db links after recovered information from the remote site?

    In addition, I propose to change your dynamic insertion in a normal insert.

    First extract the data of the DB link dynamically, but just with a select statement. Then do the insertion with the result data.

    Improve your logging table to store messages up to 4000 char CHARACTER. 200 is really small for error messages.

    In addition to the DBMS_UTILITY. FORMAT_ERROR_STACK you must also connect DBMS_UTILITY. FORMAT_ERROR_BACKTRACE. Just to see if you get a better message there.

    WHEN e_db_link_broken or e_oracle_not_available or e_oracle_down or e_no_listener or e_no_service or e_timeout THEN
       INSERT INTO DBMONITOR.DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info,FECHA_ERROR,TIPO_PROCEDURE) VALUES(var, 'Remote DB not accessible','ERROR DE CONEXION',SYSDATE,'CAPACITY');
                   -- commit;
    WHEN OTHERS THEN
    
                    INSERT INTO DBMONITOR.DBMONITOR_LOG_ERROR_TABLE (NOMBRE_DBLINK, message, info,FECHA_ERROR,TIPO_PROCEDURE) VALUES(var, SUBSTR(DBMS_UTILITY.FORMAT_ERROR_STACK||DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, 1, 4000),'ERROR DE CONEXION',SYSDATE,'CAPACITY');
                    --commit;
                    end;
    
  • ORA-01013 EXCEPTION WHILE OTHERS - behavior Undokumented?

    Hello!

    I tried to look around to find documentation on this subject, but I couldn't, so I ask here:

    As far I can understand the EXCEPTION of Oracle Documentation while OTHERS must catch not taken Exceptions supported everything!

    But then I stumbled on ORA-01013 is cancelled by the user. And who slips up WHILE OTHERS just

    DECLARE
      e_cancelled EXCEPTION
    ;
      PRAGMA EXCEPTION_INIT
    (e_cancelled, -1013);
    BEGIN
     
    BEGIN
        RAISE e_cancelled
    ;
      EXCEPTION
       
    WHEN OTHERS THEN

          -- All Exceptions should be logged here, but starting with Patch 11.2.0.4.0

           -- WHEN OTHERS is NO LONGER TRIGGERED :-o what to do???
          DBMS_OUTPUT
    .PUT_LINE('EXCEPTION OTHERS');
     
    END;

    EXCEPTION
     
    WHEN e_cancelled THEN

        -- The Exception has to be handled individually
        DBMS_OUTPUT
    .PUT_LINE('EXCEPTION CANCELLED');
    END;
    /

    My research led me to the Oracle Changelogs, that show with the last update "ORA-01013 is not caught by OTHERS more»

    So this seems to be be desired (although undocumented?) behavior... https://support.Oracle.com/epmos/faces/DocumentDisplay?ID=12838063.8

    My Question:

    We use detailed error logging and tracing in our data base, capture of logging and reraising errors THEN having "than OTHERS"
    is there a setting or parameter to let the Manager WHEN OTHERS catch this exception, or do I have to change hundreds
    packages to insert an extra WHEN ORA-01013 in each method?

    Outside the logging of errors, what is with the closing of cursors, freeing resources? Because there is no block finally in

    PL/SQL, I usually use BEGIN, EXCEPTION, END as a try-catch block and cleaning after the exception block, but when

    a timeout occurs, will be simply ignored all this code cleaning?

    Post edited by: FalcoW Link to Oracle Changelog for a better understanding when the change occurred.

    Ok... Oracle confirmed Support:

    1. This is the desired behavior, that WHEN OTHERS catches all exceptions (i.e. ORA-01013, ORA-31013, ORA-...)

    2. you are not supposed to catch - if the user cancels (or a session Times Out or JDBC accident) you should not connect anything, or do any cleaning... because the immediate release requested customer, you must immediately leave - even if it breaks your data.

    3. There is no work around known, except intercepting explicitly any special exceptions (which are not completely documented and may change at any time in the future)

    then... unlucky :-/

  • The exception of procedure management


    Hello guys,.

    I have a code below:

    BEGIN

    -Appeal procedure B;

    END;

    B() PROC

    AS

    USER_DEF EXCEPTION;

    BEGIN

    IF < SOME_CONDITION > THEN

    RAISE USER_DEF;

    END IF;

    END;

    I want to throw an exception of PROCEDURE B and want to handle in the calling PL/SQL block.

    IS THIS POSSIBLE?

    Can anyone guide me on this please?

    Thank you

    Rajendra

    Hello

    given that the exception is defined in B the calling procedure may not see it.

    You can create a package with your exceptions, then B would raise errorpackage.user_def and the calling procedure can check WHEN errorpackage.user_def.

    Concerning

    Marcus

    Edit:

    Example of

    CREATE or REPLACE PACKAGE my_errors

    AS

    e_user_defined EXCEPTION;

    c_user_defined CONSTANT INTEGER: =-20500;

    PRAGMA EXCEPTION_INIT (e_user_defined,-20500);

    ...

    Now, you can

    RAISE my_errors.e_user_defined;

    and search for

    WHEN my_errors.e_user_defined THEN

    And your exception will be associated with SQLCODE-20500

    See also 101 PL/SQL: exception handling

Maybe you are looking for