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.

Tags: Database

Similar Questions

  • 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, 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);

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

  • Execpetion manipulation of procedure

    Hello

    I'm fairly new to PLSQL and stuck with management of exceptions with a particular procedure.

    I have a procedure which takes two parameters job_id and department_id as input and based on these values, that certain actions are performed on the employees table.

    I would like to declare 2 INVALID_JOB_ID and INVALID_DEPT_ID exceptions such that when bad job_id is padded INVALID_JOB_ID is raised as an exception and what bad department_id went INVALID_DEPT_ID is fired as an exception.

    Here is the code of procedure.

    create or replace procedure (job_sal_raise)
    j_job_id IN employees.job_id%type,
    j_dept_no IN employees.department_id%type,
    j_pct in numbers
    )

    as

    j_empno employees.employee_id%type;
    j_old_sal employees.salary%type;
    j_new_sal employees.salary%type;
    J_by_whom varchar2 (50);
    j_chg_time timestamp default current_timestamp;
    j_raise employees.salary%type;


    invalid_job_id EXCEPTION;
    invalid_dept_id EXCEPTION;

    cursor c_job_sal_raise is
    Select employee_id, salary
    employees
    where employees.department_id = job_sal_raise.j_dept_no
    and employees.job_id = job_sal_raise.j_job_id;

    Start
    Open c_job_sal_raise;
    LOOP
    EXTRACT the c_job_sal_raise in j_empno j_old_sal;
    When the output c_job_sal_raise % notfound;
    j_new_sal: = (j_old_sal + j_old_sal *(j_pct/100));
    setting a day of employees set employees.salary = j_new_sal where employees.employee_id = j_empno;
    Select the user in double j_by_whom;
    insert into values of sal_audit (j_empno, j_old_sal, j_new_sal, j_chg_time, j_by_whom);
    commit;
    END LOOP;
    Select sum (new_sal) - sum (old_sal) j_raise from sal_audit where date_of_change = job_sal_raise.j_chg_time;
    insert into incr_sal_exp (j_chg_time, j_raise) values;
    commit;
    END;
    /

    See you soon

    K

    Maybe you're looking for this

    / * Formatted on 20/01/2016 13:02:04 (PS5 v5.256.13226.35510) * /.

    CREATE OR REPLACE PROCEDURE job_sal_raise)

    j_job_id IN employees.job_id%TYPE,

    j_dept_no IN employees.department_id%TYPE,

    j_pct in NUMBERS)

    AS

    j_empno employees.employee_id%TYPE;

    j_old_sal employees.salary%TYPE;

    j_new_sal employees.salary%TYPE;

    J_by_whom VARCHAR2 (50);

    j_chg_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP;

    j_raise employees.salary%TYPE;

    invalid_job_id EXCEPTION;

    invalid_dept_id EXCEPTION;

    l_cnt number;

    PRAGMA EXCEPTION_INIT(invalid_job_id,-20001);

    PRAGMA EXCEPTION_INIT(invalid_dept_id,-20002);

    CURSOR c_job_sal_raise

    IS

    SELECT employe_id, salary

    Employees

    WHERE employees.department_id = job_sal_raise.j_dept_no

    AND employees.job_id = job_sal_raise.j_job_id;

    BEGIN

    Select count (*) in the l_cnt of employees where department_id = job_sal_raise.j_dept_no;

    If l_cnt = 0 then

    RAISE invalid_dept_id;

    end if;

    Select count (*) in the l_cnt of employee where job_id = job_sal_raise.j_job_id;

    If l_cnt = 0 then

    RAISE invalid_job_id;

    end if;

    OPEN c_job_sal_raise.

    LOOP

    EXTRACT c_job_sal_raise INTO j_empno, j_old_sal;

    EXIT WHEN c_job_sal_raise % NOTFOUND;

    j_new_sal: = (j_old_sal + j_old_sal * (j_pct / 100));

    UPDATE employees

    SET employees.salary = j_new_sal

    WHERE employees.employee_id = j_empno;

    SELECT the USER IN j_by_whom FROM DUAL;

    INSERT INTO sal_audit

    VALUES (j_empno,

    j_old_sal,

    j_new_sal,

    j_chg_time,

    j_by_whom);

    COMMIT;

    END LOOP;

    SELECT SUM (new_sal) - SUM (old_sal)

    IN j_raise

    OF sal_audit

    WHERE date_of_change = job_sal_raise.j_chg_time;

    INSERT INTO incr_sal_exp

    VALUES (j_chg_time, j_raise);

    COMMIT;

    END;

    /

    I recommend you go through the following documentation

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/errors.htm

  • Invalid file operation

    Hello world

    I need to recover a file from the operating system using an Oracle procedure. To do this. All I need is to try to use a different file name and capture that in a table of newspaper (to test the object).

    Currently, when I run my procedure by incorrect filename it throws an error "invalid file Operation.

    Is it possible, where my procedure will not throw this error and instead it will run the procedure and the paper in the table of my error is "bad file name" or something like that.

    in any case I found it. I used this:

    INVALID_FILE_OPERATION EXCEPTION;

    PRAGMA EXCEPTION_INIT (INVALID_FILE_OPERATION,-29283);

    Thank you

  • How to create and insert data with Execute Immediate?

    Hi guys

    Am stuck on a procedure of formatting in a package... script works okay however integrating a module turns out to be difficult!

    Am not used to oracle... I have the script runs, but not in the package... Well not all that... Drop Table worked

    CREATE or REPLACE PACKAGE BODY is

    PROCEDURE DropTable1 IS

    BEGIN

    run immediately ("DROP TABLE mytable1");

    END;

    PROCEDURE PopulateTable1 IS

    BEGIN

    immediately execute ('CREATE TABLE mytable1 )

    AS LONG AS)

    Select

    substr (T1.genarea, 3, 3) as M_Class,

    substr (T1.genarea, 6, 30) as M_Description,

    substr (T1.genarea, 36, 3) as M_Class,

    substr (T1.genarea, 39, 30) as M_Description,

    substr (T1. ItemItem, 1, 3) as product_code,.

    T3. CHANNEL_NUM as SALES_CHANNEL,

    to_date(''t2.time_id'',''dd-mon-yyyy'') as mis_date,

    Sum (T2.ap_cw_cfi_irp + T2.ap_cw_issues_irp) as ap_gross,

    sum (t2. Ap_Cw_Cfi_Irp + t2. Ap_Revivals_Irp) as ap_net,

    Sum (T2.sp_inc_irp + T2.sp_issues_irp) as sp_gross,

    Sum (T2.sp_dec_irp + T2.sp_fs_irp) as sp_net

    Of

    d_pr t1, t2 age_map t3 law

    where

    T1.pfx = "WE"and t1.coy ="1" and t1.tabl = "T81" and substr (t1.itemitem, 1, 3) = t2.product_id and t3. AGE_NUM = t2.age_id

    Group

    substr (T1.genarea, 3, 3),

    substr (T1.genarea, 6, 30),

    substr (T1.genarea, 36, 3),

    substr (T1.genarea, 39, 30),

    substr (T1. ItemItem, 1, 3).

    T3. CHANNEL_NUM,

    to_date(''t2.time_id'',''dd-mon-yyyy'')

    )');

    COMMIT;

    END PopulateTable1;

    END test;

    /

    Thank you

    Hello

    a few notes.

    1. to_date(t2.time_id,'dd-mon-yyyy')

    New York T2.Time_ID Cis the varchar2 data type that contains values to JJ-me-YYYY format?

    And if, in which language is used for the names of the months? Conversions are point impossible to solve in reasonable time limits without logging of dml errors and unique failure on charges of staging nightly!


    2 single quote escaping "alternative in string literals.

    You can use Q or q to escape single quotes in strings.

    http://docs.Oracle.com/database/121/SQLRF/sql_elements003.htm#SQLRF00218

    3. validation

    Not required because the DDL commands commit implied.

    In general I recommend you write commit clauses only in calling script rather than in the code unless it connects with an autonomous transaction.

    You end up with a lot of validation of code here and there and you don't know where it is and where it isn't. That is, your process may have more than one appeal process and commit the middle of the process, it is not atomic processes.

    Here's the demo although I recommend also using the static table and truncate to efficiency. ETG is good choice for the purpose of maintenance table.

    create or replace
    package testing is
      procedure staging_one;
    end;
    /
    create or replace
    package body testing is
      --
      procedure staging_one is
        --
        procedure drop_staging_one is
          table_does_not_exist exception;
          pragma exception_init(table_does_not_exist, -00942);
        begin
          execute immediate q'{
            drop table staging_one purge
          }';
        exception when table_does_not_exist then
          return; -- fine
        end;
        --
        procedure create_staging_one is
        begin
          execute immediate q'{
    
            -- remove >>>
            create table staging_one nologging
            as
            select * from dual
            -- <<< remove
    
            /* uncomment >>>
            create table staging_one nologging
            as
            select
              substr(t1.genarea,3,3)                    as m_class,
              substr(t1.genarea,6,30)                   as m_description,
              substr(t1.genarea,36,3)                   as m_class,
              substr(t1.genarea,39,30)                  as m_description,
              substr(t1.itemitem,1,3)                   as product_code,
              t3.channel_num                            as sales_channel,
              to_date(t2.time_id,'dd-mon-yyyy')         as mis_date,
              sum(t2.ap_cw_cfi_irp+t2.ap_cw_issues_irp) as ap_gross,
              sum(t2.ap_cw_cfi_irp+t2.ap_revivals_irp)  as ap_net,
              sum(t2.sp_inc_irp   +t2.sp_issues_irp)    as sp_gross,
              sum(t2.sp_dec_irp   +t2.sp_fs_irp)        as sp_net
            from
              d_pr t1,
              act t2,
              age_map t3
            where
              t1.pfx                      = 'IT'
              and t1.coy                  = '1'
              and t1.tabl                 = 'T81'
              and substr(t1.itemitem,1,3) = t2.product_id
              and t3.age_num              = t2.age_id
            group by
              substr(t1.genarea,3,3),
              substr(t1.genarea,6,30),
              substr(t1.genarea,36,3),
              substr(t1.genarea,39,30),
              substr(t1.itemitem,1,3),
              t3.channel_num,
              to_date(t2.time_id,'dd-mon-yyyy')
            <<< uncomment */
          }';
          --
        end;
      -- main
      begin
        drop_staging_one;
        create_staging_one;
      end;
    end;
    /
    
    set serveroutput on
    
    exec testing.staging_one;
    
    select * from staging_one
    ;
    commit
    ;
    
    PACKAGE TESTING compiled
    PACKAGE BODY TESTING compiled
    anonymous block completed
    DUMMY
    -----
    X 
    
    committed.
    
  • Can not validated against the schema

    I have the following XML

    < HTNG_HotelRoomStatusSearchRS

    " xmlns: ota = ' http://www.OpenTravel.org/OTA/2003/05 "" "

    " xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "

    Version = "7,000".

               xmlns=" http://HTNG.org/2014B "

    " xsi: schemaLocation =" http://HTNG.org/2014B ' HTNG_HotelRoomStatusSearchRS.xsd '

    TimeStamp = "" 2015-04 - 29 T 15: 42:25Z ""

    Target = "Test" TargetName = "AUS".

    TransactionIdentifier = "12345" >

    < success > < / success > < errors > < error Type = '0' doc 'None' = > < / error > < / errors >

    < RoomInformationList >

    < TPA_Extensions >

    < TPA_Extension > < DEVICE UNIT_NUM = "pm_unit_num" UNIT_TYPE = "pm_unit_type_desc" HSK_DESC = "CLN".

    ROOM_STATUS = "EMPY" STATUS_CODE = 'HERE', ARRIVAL_DATE = 'NOW' DEPARTURE_DATE = 'THEN' RESV_TYPE = 'RT '.

    "DRI_PROP_ID ="DPI"RESV_NUM ="RN"CREATE_DATE ="CD"MC_PROPERTY_CODE ="MPC"HOTEL_DATE =" HD "SERVICE_CODE = 'SC' > < / UNIT >

    < / TPA_Extension > < / TPA_Extensions > < / RoomInformationList > < / HTNG_HotelRoomStatusSearchRS >

    I'm trying to validate

    <? XML version = "1.0" encoding = "UTF-8"? >

    " < xs: schema xmlns: XS =" http://www.w3.org/2001/XMLSchema "

                       xmlns=" http://HTNG.org/2014B "

    " xmlns: ota = ' http://www.OpenTravel.org/OTA/2003/05 "" "

    " targetNamespace = ' http://HTNG.org/2014B "

    oraxdb:numProps = "6".

    elementFormDefault = "qualified".

    version = "1.000".

    ID = "HTNG2014B".

    ' xmlns:oraxdb = ' http://xmlns.Oracle.com/xdb "" "

    oraxdb:storeVarrayAsTable = 'true '.

    oraxdb:flags = "2105635".

    oraxdb:schemaURL = "HTNG_HotelRoomStatusSearchRS.xsd"

    oraxdb:schemaOwner = "CLY" >

    < xs: include schemaLocation = "HTNG_SimpleTypes.xsd" / >

    < xs: include schemaLocation = "HTNG_CommonTypes.xsd" / >

    " < xs: import namespace = ' http://www.OpenTravel.org/OTA/2003/05 "schemaLocation ="OTA_CommonTypes.xsd"/ > "

    < xs: annotation >

    < intention XML: lang = "fr" > This message is in response to a HTNG_HotelRoomStatusSearchRQ message. < / intention >

    < / xs: annotation >

    < xs: element name = "HTNG_HotelRoomStatusSearchRS" oraxdb:propNumber = '7324' oraxdb: global = "true" oraxdb:SQLName = "HTNG_HotelRoomStatusSearchRS" oraxdb:SQLType = "HTNG_HotelRoomStatusSea2173_T" oraxdb:SQLSchema = "CLY" oraxdb:memType "258" = >

    < complexType oraxdb:SQLType = "HTNG_HotelRoomStatusSea2173_T" oraxdb:SQLSchema = "CLY" >

    < xs:complexContent >

    < xs:extension base = "HTNG_ResponseBaseType" >

    < xs: SEQUENCE >

    < xs: element name = "RoomInformationList" oraxdb:propNumber = '7323' oraxdb: global = "false" oraxdb:SQLName = "RoomInformationList" oraxdb:SQLType = "RoomInformationList2174_T" oraxdb:SQLSchema = "CLY" oraxdb:memType = "258" oraxdb:MemInline = "false" oraxdb:SQLInline = "true" oraxdb:JavaInline = "false" >

    < xs: annotation >

    < intention XML: lang = "fr" > the result set generated by the query sent to the application. < / intention >

    < / xs: annotation >

    < complexType oraxdb:SQLType = "RoomInformationList2174_T" oraxdb:SQLSchema = "CLY" >

    < xs: SEQUENCE >

    < xs: element name = "Rooms" minOccurs = "0" maxOccurs = "unbounded" oraxdb:propNumber = '7322' oraxdb: global = 'false' oraxdb:SQLName = 'Rooms' oraxdb:SQLType = "RoomInformation2175_T" oraxdb:SQLSchema = "CLY" oraxdb:memType = "258" oraxdb:MemInline = "false" oraxdb:SQLInline = "true" oraxdb:JavaInline = "false" oraxdb:SQLCollType = "RoomInformation2176_COLL" oraxdb:SQLCollSchema = "CLY" >

    < xs: annotation >

    < intention XML: lang = "fr" > a container element used to hold room and reservation information. < / intention >

    < / xs: annotation >

    < complexType oraxdb:SQLType = "RoomInformation2175_T" oraxdb:SQLSchema = "CLY" >

    < xs: SEQUENCE >

    < xs: element name = "Room" type = "HTNG_RoomElementType" oraxdb:propNumber = '7319' oraxdb: global = "false" oraxdb:SQLName = "Room" oraxdb:SQLType = "HTNG_RoomElementType2044_T" oraxdb:SQLSchema = "CLY" oraxdb:memType = "258" oraxdb:MemInline = "false" oraxdb:SQLInline = "true" oraxdb:JavaInline = "false" >

    < xs: annotation >

    < intention XML: lang = "fr" > used to pass on information about a room or suite room components compound. < / intention >

    < / xs: annotation >

    < / xs: element >

    < xs: element name = "HotelReservations" type = "ota:HotelReservationsType" minOccurs = "0" oraxdb:propNumber = "7320" oraxdb: global = "false" oraxdb:SQLName = "HotelReservations" oraxdb:SQLType = "HotelReservationsType1709_T" oraxdb:SQLSchema = "CLY" oraxdb:memType = "258" oraxdb:MemInline = "false" oraxdb:SQLInline = "true" oraxdb:JavaInline = "false" >

    < xs: annotation >

    < intention XML: lang = "fr" > used to pass on information about the booking and/or its supporting comments. < / intention >

    < / xs: annotation >

    < / xs: element >

    < xs: element name = "TPA_Extensions" type = "ota:TPA_ExtensionsType" minOccurs = "0" oraxdb:propNumber = '7321' oraxdb: global = "false" oraxdb:SQLName = "TPA_Extensions" oraxdb:SQLType = "TPA_ExtensionsType174_T" oraxdb:SQLSchema = "CLY" oraxdb:memType = "258" oraxdb:MemInline = "false" oraxdb:SQLInline = "true" oraxdb:JavaInline = "false" >

    < xs: annotation >

    < intention XML: lang = "fr" > This is used to Exchange custom/setting values in work - specific as are agreed between the trading partners. < / intention >

    < / xs: annotation > < / xs: element > < / xs: SEQUENCE > < / xs: complexType > < / xs: element > < / xs: SEQUENCE > < / xs: complexType > < / xs: element > < / xs: SEQUENCE >

    < / xs:extension > < / xs:complexContent > < / xs: complexType > < / xs: element > < / xs: Schema >

    I'm creating the document. I can't it's the basic scheme.

    DECLARE

    CURSOR c_info

    IS

    (SELECT XMLELEMENT

    'HTNG_HotelRoomStatusSearchRS '.

    xmlattributes)

                           ' http://www.OpenTravel.org/OTA/2003/05 "AS"xmlns:ota" "

                          ,' http://www.w3.org/2001/XMLSchema-instance ' AS ' xmlns: xsi "

    , "7,000"AS "Version".

                          ,' http://HTNG.org/2014B ' AS 'xmlns'

                          ,' http://HTNG.org/2014B HTNG_HotelRoomStatusSearchRS.xsd' AS "xsi: schemaLocation"

    , TO_CHAR (SYSDATE, "DD-MM-YYYY")

    || ' T '

    || TO_CHAR (SYSDATE, 'HH24:MI:SS')

    || 'Z' AS 'TimeStamp '.

    CASE WHEN gn.global_name = 'ATLAS' AND 'Production' ELSE 'Test' END as 'Target'

    , 'AUS' AS 'TargetName '.

    "12345" AS "TransactionIdentifier")

    XMLELEMENT ("Success")

    , XMLELEMENT ("Errors", XMLELEMENT ("Error", xmlattributes ('Type', 'None' AS 'Doc' of "0")))

    XMLELEMENT ("RoomInformationList",

    XMLELEMENT ("TPA_Extensions",

    XMLELEMENT ("TPA_Extension",

    XMLELEMENT ("UNIT"

    xmlattributes ('pm_unit_num' AS 'UNIT_NUM'

    , 'pm_unit_type_desc' AS 'UNIT_TYPE.

    , "CLN" AS "HSK_DESC".

    , "EMPY" AS "ROOM_STATUS".

    , 'HERE' AS 'STATUS_CODE '.

    , "NOW" AS "ARRIVAL_DATE".

    AND 'THEN' AS 'DEPARTURE_DATE '.

    , 'RT' AS 'RESV_TYPE '.

    , "DPI" AS "DRI_PROP_ID".

    , 'RN' AS 'RESV_NUM '.

    , 'CD' AS 'CREATE_DATE.

    , "MPC" AS "MC_PROPERTY_CODE".

    , 'HD' AS 'HOTEL_DATE '.

    'SC' AS 'SERVICE_CODE')))

    AS 'RESULT '.

    FROM global_name gn;

    Tinfo TYPE IS TABLE OF c_info % ROWTYPE;

    t_guests tinfo.

    CLOB xmlDoc;

    l_xmltype XMLTYPE.

    v_schema_to_validate VARCHAR2 (2000);

    non_registered_schema EXCEPTION;

    PRAGMA EXCEPTION_INIT (non_registered_schema,-31000);

    BEGIN

    OPEN c_info.

    Get the c_info COLLECT in BULK IN t_guests;

    CLOSE C_info;

    xmlDoc: = t_guests (1).result.getstringval ();

    l_xmltype: = xmltype (doc);

    -IF l_xmltype.isschemabased () = 0 THEN RAISE non_registered_schema;  END IF;

    -v_schema_to_validate: = l_xmltype.getrootelement () | '.xsd ';

    dbms_output.put_line (v_schema_to_validate);

    dbms_output.put_line (xmldoc);

    END;

    As has been pointed out by Marco, Errors, item is imported the schema HTNG_CommonTypes.xsd.

    It is based on ErrorsType of OTA_CommonTypes.xsd, whose target namespace is http://www.opentravel.org/OTA/2003/05.

    This is why the Error element (declared in ErrorsType complexType) must be qualified by the prefix of the ota in the documents.

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

  • Error updating the WSF

    Hello

    I want to install OLIVIER 11.1.1.9.1 and updating the FSM, I get the following error:

    CREATE INDEX ASK_SP_DIS_ATTRS_MAPPING_U2 ON ASK_SP_DISPLAY_ATTRS_MAPPING (SP_ATTRIBUTE_ID, SP_DISPLAY_ATTRIBUTE_ID, ENTERPRISE_ID) SINGLE

    ');

    add_table_column ('ASK_XML_NODE_PATHS', 'EXCLUDE_FLAG', ' VARCHAR2 (1)', 'NULL', 'NULL');

    add_table_column ('ASK_XML_REQ_STATUSES', 'EXCLUDE_FLAG', ' VARCHAR2 (1)', 'NULL', 'NULL');

    add_table_column ('ASK_XML_ROWS', 'EXCLUDE_FLAG', ' VARCHAR2 (1)', 'NULL', 'NULL');

    END;

    ]

    2015-03-23 12:24:58.950 rcu:Statement Type: 'anonymous' BEGIN/END block

    JDBC SQLException - error code: 12801SQLState:72000 Message: ORA-12801: error reported in the parallel query P000 Server

    ORA-01006: there is no bind variable

    ORA-06512: at line 102

    ORA-06512: at line 217

    Encountered error the SQL statement being executed FileName: ' / u01/OBIA/MW_HOME/Oracle_BI1/biapps/admin/provisioning/update/11.1.1.7.2/from11.1.1.7.0/schema/oracle/fsm/upgrade.sql ' LineNumber: '753'

    SQL statement: [DECLARE

    PROCEDURE create_table (p_stmt VARCHAR2) IS

    TABLE_EXISTS EXCEPTION;

    PRAGMA EXCEPTION_INIT (TABLE_EXISTS,-955);

    BEGIN

    EXECUTE IMMEDIATE p_stmt;

    EXCEPTION

    WHEN TABLE_EXISTS THEN

    NULL;

    WHILE OTHERS THEN

    RAISE_APPLICATION_ERROR (-20001, "error when the CREATE_TABLE treatment for ' |") p_stmt | ' ' || SQLCODE. ' ' || SQLERRM);

    Create_table END;

    Alter_table (p_stmt VARCHAR2) PROCEDURE IS

    COLUMN_EXISTS EXCEPTION;

    PRAGMA EXCEPTION_INIT (COLUMN_EXISTS,-1430);

    ALREADY_NULL EXCEPTION;

    Please help solve the problem.

    Thank you

    Sarika

    The problem has been resolved by removing the lines the upgrade script /u01/OBIA/MW_HOME/Oracle_BI1/biapps/admin/provisioning/update/11.1.1.7.2/from11.1.1.7.0/schema/oracle/fsm/upgrade.sql drop_all_ind_and_primary_key. I don't know whether this is a known issue. My version of OLIVIER's 11.1.1.9.1 and db version 12.1.0.2.

  • Unable to see the description of the error

    Hi gurus

    I have the following code:

    Code example

    Create table

    CREATE TABLE plch_data

    (p NUMBER (1));

    ------------

    Create Procedure

    CREATE OR REPLACE

    PROCEDURE plch_test

    IS

    bulk_error exception;

    pragma exception_init (bulk_error,-24381);

    TYPE number_t

    IS

    TABLE OF NUMBER;

    l_number number_t: = number_t (1);

    BEGIN

    -l_number (1) .extend;

    l_number (1): = 100/l_number (1) / (l_number (1) - 1);

    FORall INdx IN 1.l_number.count EXCEPTIONS

    INSERT INTO plch_data VALUES

    (l_number (INdx)

    );

    EXCEPTION

    WHEN bulk_error THEN

    FOR the INd IN 1..SQL%BULK_exceptions.count

    LOOP

    dbms_output.put_line

    (

    'Error =' | SQL % BULK_exceptions (ind) .error_code

    )

    ;

    END loop;

    END;

    --------------

    Appeal procedure

    BEGIN

    plch_test;

    EXCEPTION

    WHILE OTHERS THEN

    dbms_output.put_line ('Error' |) SQLCODE);

    END;

    -----------------

    Result

    anonymous block filled

    Error-1476

    --------------

    My question is can I see error no 1476 with description of the error, how is, I see the description of the error?

    1476 = testator is zero...

    Hello

    I'm not sure that I understand, but what about SQLERRM?

    Best regards

    Bruno Vroman.

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

Maybe you are looking for