Raise_application_error

What would happen when raise_Application_error()
procedure is called in pl/sql block .
thank you

Raise_application_error is the programmers' tool to raise an exception.
So it would raise an exception...
Why not just try it?
begin
  raise_application_error(-20000,'Oops');
end;
/

Similar Messages

  • Returning both raise_application_error and return value from db function...

    Hi ,
    I use Oracle 10g and forms10g.
    I have written a db packaged function such as:
    function fnc_ipologismos_xiliometron(code_poleis_apo_var in varchar2,code_poleis_pros_var in varchar2)
       return number
       is
        apostasi_var ref_apostaseis_poleon.apostasi%type;
        onomasia_pol_apo_var ref_poleis.onomasia%type;
        onomasia_pol_pros_var ref_poleis.onomasia%type;
        begin
         begin
            select onomasia into onomasia_pol_apo_var
              from ref_poleis
              where code_poleis=code_poleis_apo_var;
         end;
         begin
            select onomasia into onomasia_pol_pros_var
              from ref_poleis
              where code_poleis=code_poleis_pros_var;
         end;
         begin
          select apostasi into apostasi_var
           from ref_apostaseis_poleon
           where code_poleis_apo=code_poleis_apo_var and code_poleis_pros=code_poleis_pros_var;
          exception
           when no_data_found
    then
    apostasi_var:=0;
    return apostasi_var;
    raise_application_error(-20015,'a message');
    --return apostasi_var;
    end;      return apostasi_var;
        end;The problem is that when the exception written above (in bold) returns 0 and exits the function.... whereas i want this value to be returned as well as the message in the raise_application_error....
    I call this function in WHEN-VALIDATE-ITEM of a block item... such as:
    if pkg_mod3_general.fnc_ipologismos_xiliometron
    (:mod3_entoli_metakinisis.code_poleis_apo_type_id,:mod3_entoli_metakinisis.code_poleis_type_id)=0
                  and :mod3_entoli_metakinisis.seq_code_meso_metakin_type_id=2
                  then
                    raise form_trigger_failure;
      end if;     When the above condition is true then no message is displayed and the cursor sticks to the item(as the raise_application_error in the db packaged function is after the exit of the function) and when the condition is false then no message is displayed again ... as expected.....
    How is it get the desired result.....- get the message from the raise_application_error and the function returns 0.....?????
    Many thanks,
    Simon

    you cannot RETURN and RAISE a function.
    RETURN ends the function immediately
    RAISE ends the program unit and jumps in the EXCEPTION-Handler, if it exists. Else the function ends

  • Need help in raise_application_error()

    Hi All,
    The below code is working but when there is no vehicle_id,
    the exception is not raised.
    1.How do i use the raise_application_error
    2.how do i get the value of R.vin_cd,r.assc_nm_cd after closing the cusor
    as i want to insert those values in error log.
    3. do i need to do any changes to my code
    Please help
    CREATE OR REPLACE PROCEDURE ODS_LOAD_FUEL
    IS
    v_CREATED_BY_NM      := 'SYSTEM';
    v_CREATED_DTM := SYSDATE;
         v_assc_id number;
         v_id number;
         e_no_ASSC_vehicle_ID_FOUND EXCEPTION;
         v_asgnmt_dt date;
         v_ErrText varchar2(250);
         v_errnbr number;
    BEGIN
         FOR R IN (SELECT vin_cd,assc_nm_cd FROM STG_FUEL)
         LOOP
              select assc_id,vehicle_id,vehicle_asgnmt_dt into v_assc_id,v_id,v_asgnmt_dt
              from vehicle_asgnmt
    where           vehicle_id = get_curr_vin_cd(R.vin_cd);
         IF ( v_id is not null) THEN
    BEGIN
         INSERT INTO VEHICLE_FUEL_CLAIM
                   VEHICLE_FUEL_CLAIM_ID,
                   ODOMETER_MILEAGE_NUM,
                   FUEL_GALLON_QTY,
                   ASSC_ID,
                   VEHICLE_ID,
                   VEHICLE_ASGNMT_DT,
                   CREATED_BY_NM,
                   CREATED_DTM)
              ( select FUEL_SEQ.nextval,
                             1000,
              a.FUEL_GALLONS_QTY,
              v_assc_id,
              v_id,
              v_asgnmt_dt,
              v_CREATED_BY_NM,
              v_CREATED_DTM
                             FROM STG_FUEL a
                                  WHERE a.vin_cd=R.vin_cd
                                  and a.assc_nm_cd=R.assc_nm_cd );
    END;
    ELSE
    v_ErrText:='Not in vehicle-assignment';
              RAISE e_no_ASSC_vehicle_ID_FOUND;
         END IF;
    END LOOP;
    COMMIT;
    EXCEPTION
              WHEN e_no_ASSC_vehicle_ID_FOUND THEN
              RAISE_APPLICATION_ERROR(-20001,'No rows in vehicle_asgnmt. Fatal error.');
              v_errnbr :=-20001;
              v_ErrText := 'No rows in ASSC. Fatal error.';
    insert into error_log VALUES(v_errnbr,v_ErrText,'there is no data found for vin#=','adr','I','INTERFACE_NAME',sysdate);
    WHEN OTHERS THEN
              v_errnbr := sqlcode;
              v_ErrText := dbms_utility.format_error_stack;
    insert into error_log VALUES(v_errnbr,v_ErrText,'there is no assc_id found for NM#=','adr','I','INTERFACE_NAME',sysdate);
         dbms_output.put_line('after others');
    END LOOP;
    COMMIT;
    END;
    /

    hi,
    here is the code : i made few changes
    exception is not raising when there is no data.
    CREATE OR REPLACE PROCEDURE ODS_LOAD_FUEL1
    IS
         v_CREATED_BY_NM      := 'SYSTEM';
    v_CREATED_DTM := SYSDATE;
         v_assc_id number;
         v_id number;
         e_no_ASSC_vehicle_ID_FOUND EXCEPTION;
         v_asgnmt_dt date;
         v_ErrText varchar2(250);
         v_errnbr number;
    BEGIN
         FOR R IN (SELECT * FROM STG_FUEL)
         LOOP
         dbms_output.put_line(r.vin_cd);
         dbms_output.put_line(r.assc_nm_cd);
              select assc_id,
    vehicle_id,
    vehicle_asgnmt_dt into v_assc_id,
    v_id,
    v_asgnmt_dt
              from vehicle_asgnmt
    where vehicle_id = get_curr_vin_cd(R.vin_cd);
         dbms_output.put_line(v_assc_id);
         dbms_output.put_line(v_id);
         dbms_output.put_line(v_asgnmt_dt);
         IF ( v_id is not null) THEN
    --BEGIN
         dbms_output.put_line('Inside inner begin');
         dbms_output.put_line('before insert');
         INSERT INTO VEHICLE_FUEL_CLAIM
                   VEHICLE_FUEL_CLAIM_ID,
                   ODOMETER_MILEAGE_NUM,
                   FUEL_GALLON_QTY,
                   ASSC_ID,
                   VEHICLE_ID,
                   VEHICLE_ASGNMT_DT,
                   CREATED_BY_NM,
                   CREATED_DTM)
              ( select FUEL_SEQ.nextval,
                   1000,
              a.FUEL_GALLONS_QTY,
              v_assc_id,
              v_id,
              v_asgnmt_dt,
              v_CREATED_BY_NM,
              v_CREATED_DTM
              FROM STG_FUEL a
              WHERE a.vin_cd=R.vin_cd
              and a.assc_nm_cd=R.assc_nm_cd );
    dbms_output.put_line('after insert');
    --END;
    dbms_output.put_line('after inner begin');
    ELSE
    dbms_output.put_line('else of main begin');
    v_ErrText:='Not in vehicle-assignment';
         RAISE e_no_ASSC_vehicle_ID_FOUND;
         END IF;
    END LOOP;
    COMMIT;
    EXCEPTION
              WHEN e_no_ASSC_vehicle_ID_FOUND THEN
              RAISE_APPLICATION_ERROR
    (-20001,'No rows in vehicle_asgnmt. Fatal error.');
              v_errnbr :=-20001;
              v_ErrText := 'No rows in ASSC. Fatal error.';
    insert into error_log VALUES(v_errnbr,v_ErrText,'there is no data found for vin#=','adr','I','INTERFACE_NAME',sysdate);
         dbms_output.put_line('after raise');
    WHEN OTHERS THEN
              v_errnbr := sqlcode;
              v_ErrText := dbms_utility.format_error_stack;
    insert into error_log VALUES(v_errnbr,v_ErrText,'there is no assc_id found for NM#=','adr','I','INTERFACE_NAME',sysdate);
         dbms_output.put_line('after others');
    --END LOOP;
    --COMMIT;
    END;
    /

  • RAISE_APPLICATION_ERROR works only in exception block

    Hi,
    I am facing a strange issue. My RAISE_APPLICATION_ERROR wroks only in EXCEPTION block and not in BEGIN block. Please have a look at below description
    I have a procedure that has IF Block as shown below.
    BEGIN
    IF TO_DATE('31-DEC-99', 'DD-MON-RR') > TO_DATE('11-MAR-12', 'DD-MON-RR') THEN
    RAISE_APPLICATION_ERROR(-20001, 'some message');
    END IF;
    END;
    -- RAISE_APPLICATION_ERROR is not working in the above code.
    BEGIN
    IF TO_DATE('31-DEC-99', 'DD-MON-RR') > TO_DATE('11-MAR-12', 'DD-MON-RR') THEN
    RAISE EX_ABC
    END IF;
    EXCEPTION
    WHEN EX_ABC THEN
    RAISE_APPLICATION_ERROR(-20001, 'some message');
    END;
    --Here the exception is raised and it works fine.
    BACKDROP:
    I have made a trigger that does date validations. It calls procedure for all the validations. And the above shown code is a part of the validations that the procedure does.
    Please help.
    Edited by: Ishan on Mar 14, 2012 1:28 PM
    Edited by: Ishan on Mar 14, 2012 1:31 PM

    Ishan wrote:
    I have myself checked and tested with all these conditions. Tried all to_date formats and dbms_output to be sure of the values but nothing seems to work.
    It works in a sample code. But when implemented in the procedure it is ignoring the RAISE_APPLICATION_ERROR.
    Condition is correct. Below is the logic because of which I can say it's correct
    If 1=1 then
    raise_application_error (-20001, 'ABC');
    end;
    this ignores the raise_application_error.
    However if I modify the code with exception block, WITHOUT CHANGING THE CONDITION, iti works fine
    if 1=1 then
    raise ex_ab
    exception
    raise_application_error (-20001, 'ABC');
    end;
    Now the exception is raised.
    NOTE: EVen if I am using 1=1 condition in my code, it is still ignoring the RAISE_APPLICATION error but it will raise the same in he exception block.
    Not sure how is this possible.Are you saying the below code is giveing different result in your db?
    BEGIN
    IF 1=1 THEN
    RAISE_APPLICATION_ERROR(-20001, 'some message');
    END IF;
    END;

  • Sqlj fails with call to raise_application_error

    I get an error
    Invoking loadjava on connection 'dbm1_twebn1' with arguments:
    -order -resolve -thin -verbose
    creating : class SystemDaemon/testcase
    loading : class SystemDaemon/testcase
    resolving: class SystemDaemon/testcase
    errors : class SystemDaemon/testcase
    ORA-29521: referenced name sqlj/runtime/ExecutionContext$OracleContext could not be found
    The following operations failed
    class SystemDaemon/testcase: resolution
    when I load this sqlj file
    in an 8.1.7 database
    package SystemDaemon;
    import sqlj.runtime.*;
    import sqlj.runtime.ref.*;
    import java.sql.*;
    import oracle.sqlj.runtime.*;
    public class testcase
    static public void testcase1()
    String s = new String("this is a test");
    try
    #sql {CALL RAISE_APPLICATION_ERROR(-20020, :s)};
    catch (SQLException e)
    // putLine("error in raise_application_error" + e.getMessage());
    This works fine in a 9i database
    I get other errors when i load the source code into the database but I get thoses in both 8i and 9i.
    any sugestions on how to fix this?
    Daniel Smith
    [email protected]

    It appears that you are translating SQLJ using the 9i version of the SQLJ
    translator and loading that into an 8i database. The SQLJ code that
    is generated by default requires a 9i (or later) version of the SQLJ runtime
    and JDBC driver as well. The 8i database only has the 8i SQLJ runtime available to it.
    You can turn on backwords compatibility for your SQLJ code with the option:
    -codegen=iso
    This generates standard SQLJ code (including .ser files that contain the code
    of your SQLJ statements) that can be used in 8i as well as in 9i - just make
    sure you load both, .ser and .class files into the database (or use the
    -ser2class option to convert .ser into .class files). Or, just load the source
    directly into the database.
    Please note an additional caveat when generating code with SQLJ. If you
    translate code with the 9.0.1 JDBC driver in the CLASSPATH, then this
    code will run under 9.0.1 and later (such as 9.2) JDBC drivers. However,
    the converse is not true: if you use a 9.2 JDBC driver during translation,
    the generated code will utilize 9.2-specific JDBC APIs and may not run
    under 9.0.1 JDBC. Thus to get compatibility: either use the -codegen=iso
    option, or make sure that when your code is run you use the same or
    a later JDBC driver than what you used when the code was translated.
    Hope this helps.
    -- Ekkehard

  • Last parameter in the raise_application_error  (true or false)

    Hi everyone,
    I have a question reagrding the last parameter in the raise_application_error clause.
    The last parameter says
    true: purge error stack
    false: do not purge error stack.
    I raised an exception and captured it with both parameters.
    In the case of false(do not purge previous errors) I could see the exect error no and msg (like No data found).
    But in the case of true (purge previous errors) i got an exception, but not the exact error msg.
    Is this the difference.
    In the case of true, it should purge previous errors, why is it purging the most recent error also.
    Is there anything more to true and false. Please highlight.
    And is there a way i can see the error stack.
    I am so keen to see that.
    It always says error is placed on the stack of previous errors.
    I want to see the previous errors.
    Can I.
    Any ideas.
    meenakshi

    See:
    http://www.oracle.com/technetwork/issue-archive/2005/05-mar/o25plsql-093886.html
    DBMS_UTILITY.FORMAT_ERROR_BACKTRACE

  • Raise_application_error is not displaying error message in my form

    Hi,
    I have created one procedure in order to display the error message in front end forms.But which is not display the error message in my form when call the procedure.
    Please refer the code.
    BEGIN
    IF C_ERR%ISOPEN THEN
    CLOSE C_ERR;
    END IF;
    OPEN C_ERR;
    FETCH C_ERR INTO M_ERR_ARB_DESC;
    CLOSE C_ERR;
    RAISE_APPLICATION_ERROR(-20001,P_ERROR_CODE||' - '||M_ERR_ARB_DESC);
    END;
    Thanks & advance
    Regards
    Maran

    Hi,
    -------form program unit------
    PROCEDURE RAISE_APP_ERR(P_ERR_CODE NUMBER) IS
    alert_button NUMBER;
    Raise_Exception EXCEPTION;
    PRAGMA EXCEPTION_INIT(Raise_Exception, -20001);
    BEGIN
    --- called backend procedure
    PRC_RAISE_APPLICATION(P_ERR_CODE);
    EXCEPTION
    WHEN Raise_Exception THEN
    alert_button := SHOW_ALERT('raise_alert');
    If alert_button = ALERT_BUTTON1 Then
    Raise FORM_TRIGGER_FAILURE;
    End If;
    END;
    ---------- db proc----
    CREATE OR REPLACE PROCEDURE PRC_RAISE_APPLICATION(P_ERROR_CODE IN HRM_ERR_CODE.HEC_ERR_CODE%TYPE
    ) AS
    CURSOR C_ERR IS
    SELECT HEC_ERR_ARB_DESC
    FROM HRM_ERR_CODE
    WHERE HEC_ERR_CODE = P_ERROR_CODE;
    M_ERR_ARB_DESC HRM_ERR_CODE.HEC_ERR_ARB_DESC%TYPE;
    BEGIN
    IF C_ERR%ISOPEN THEN
    CLOSE C_ERR;
    END IF;
    OPEN C_ERR;
    FETCH C_ERR INTO M_ERR_ARB_DESC;
    IF C_ERR%NOTFOUND THEN
    M_ERR_ARB_DESC := 'UNKNOWN ERROR ';
    END IF;
    CLOSE C_ERR;
    RAISE_APPLICATION_ERROR (-20001, P_ERROR_CODE||' - '||M_ERR_ARB_DESC);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    RAISE_APPLICATION_ERROR (-20001, P_ERROR_CODE||'-'||'UNKNOWN ERROR ');
    END ;
    I tried the same but still i am not getting error message in Forms.

  • Getting raise_application_error code using  php

    I have a trigger that catches an action and returns a raise_application_error. I am having a hard time finding out how to retrieve the error code (I defined it) using php code.
    here is an example of the php/oracle error message that I get:
    Warning: OCIStmtExecute: ORA-21000: error number
    argument to raise_application_error of -2006 is
    out of range ORA-06512
    I can retrieve the oracle predefined error code (21000) using
    $oci_error = OCIError($statement);
    $oci_error["code"];
    but do not know how to get the (-2006) except maybe parseing the $oci_error["message'].

    nevermind, figured it out. my raise_application_error was out of range (like the error message said O=) )
    changing it to -20006 (instead of -2006) works.
    karn

  • Inserting rows although the raise_application_error is raised

    Hi,
    I have created two triggers on a table (one before insert and the other after insert).
    The after trigger calls a procedure...
    The before insert trigger is as follows:
    create or replace trg_
    before insert on xf
    or each row
    begin
    select a_date from y
    where ...;
    if x>:new.date_of_a_table_inserted_via_a_form
    then
    raise_application_error....
    end if;
    end;
    Altough i insert a date value equal to a_date - not previous to a date which has already been inserted the trigger displays the error message (raise_application_error....(message)) but the row(s) are inserted....in the table.... Can you spot what may be wrong...????
    many thanks,
    Simon

    The reason for this phenomenon (although an alert is displayed, the record is saved in the database) seems to be the ON-ERROR .pll library i have attached to the form....
    The db trigger works absolutely right.....(to answer to a previous question/note)
    In this library i have written if..elsif...elsif....end if; construct in order to catch various db errors.... The problem is focused in the management of user-defined errors , i have written in db triggers mainly.....
    Can you pinpoint the error.....in bold below????
    I have also pasted the code for errors (-2291,-1,-2290) in order - maybe- the logic.....
    PROCEDURE PRC_DISPLAY_ERROR IS
      CONSTRAINT_NAME_VAR ALL_CONSTRAINTS.CONSTRAINT_NAME%TYPE;
      AL_ID ALERT;
      AL_N NUMBER;
      DBMS_ERROR_CODE_VAR NUMBER;
      DBMS_ERROR_TEXT_VAR VARCHAR2(3000);
      DBMS_ERROR_FIELD_VAR VARCHAR2(30);
      DBMS_ERROR_TEXT_TABLE_VAR VARCHAR2(60);
      ALERT_CODE_VAR REF_ALERTS.ALERT_CODE%TYPE;
      ALERT_MSG_VAR REF_ALERTS.ALERT_MSG%TYPE;
      HELP_MSG_VAR REF_ALERTS.HELP_MSG%TYPE;
      INSTR_APO NUMBER(3);
      INSTR_EOS NUMBER(3);
      LENGTH_VAR NUMBER(3);
      INSTR_APO_TABLE NUMBER(3);
      INSTR_EOS_TABLE NUMBER(3);
      LENGTH_TABLE_VAR NUMBER(3);
      SEARCH_CONDITION_VAR ALL_CONSTRAINTS.SEARCH_CONDITION%TYPE;
      CONSTRUCTED_TEXT_VAR VARCHAR2(4000);
      CONSTRUCTED__TEXT_VAR VARCHAR2(4000);
      ALL_STRING_VAR VARCHAR2(600);
      FIELD_VAR VARCHAR2(30);
      FIELD_VAR_ VARCHAR2(30);
      TABLE_VAR VARCHAR2(30);
    BEGIN
                               /*DBMS - ERRORS*/
         DBMS_ERROR_TEXT_VAR:=DBMS_ERROR_TEXT;
         DBMS_ERROR_CODE_VAR:=DBMS_ERROR_CODE;
                               /* FOREIGN/PRIMARY KEY , CHECK CONSTRAINT...*/
         IF DBMS_ERROR_CODE_VAR IN (-2291,-1,-2290)
           THEN
                 INSTR_APO:=INSTR(DBMS_ERROR_TEXT_VAR,'.',1)+1;
                 INSTR_EOS:=INSTR(DBMS_ERROR_TEXT_VAR,')',1);
                LENGTH_VAR:=INSTR_EOS-INSTR_APO;
                   DBMS_ERROR_TEXT_VAR:=SUBSTR(DBMS_ERROR_TEXT_VAR,INSTR_APO,LENGTH_VAR);                    
                BEGIN
                     SELECT DISTINCT B.ALERT_CODE , ALERT_MSG , HELP_MSG INTO ALERT_CODE_VAR , ALERT_MSG_VAR , HELP_MSG_VAR
                        FROM REF_ALERTS_DET A, REF_ALERTS B
                        WHERE A.ALERT_CODE=B.ALERT_CODE
                        AND CONSTRAINT_NAME = DBMS_ERROR_TEXT_VAR;
                     EXCEPTION
                           WHEN NO_DATA_FOUND
                            THEN
                               AL_ID:=FIND_ALERT('AL_NOTE');
                               AL_N:=SHOW_ALERT(AL_ID);
                  RETURN;
                     END;
                     AL_ID:=FIND_ALERT('AL_STOP');
            SET_ALERT_PROPERTY(AL_ID,ALERT_MESSAGE_TEXT,ALERT_MSG_VAR||'.'||HELP_MSG_VAR);
            AL_N:=SHOW_ALERT(AL_ID);
    elsif ......
    elsif.....
    elsif DBMS_ERROR_CODE_VAR IN (-20000,-20001,-20002,-20003,-20004,-20005,-20005,-20006,-20007,-20008,-20009,-20010,
         -20011,-20012,-20013,-20014,-20015,-20016,-20017,-20018,-20019,-20020,-20021,-20022,
         -20023,-20024,-20025,-20026,-20027,-20028,-20029,-20030,-20031,-20032,
         -20033,-20034,-20035,-20036,-20037,-20038,-20039,-20040,-20041,-20042,
         -20043,-20044,-20045,-20046,-20047,-20048,-20049,-20050,-20051,-20052,
         -20053,-20054,-20055,-20056,-20057,-20058,-20059,-20060,-20061,-20062,
         -20063,-20064,-20065,-20066,-20067,-20068,-20069,-20070,-20071,-20072,
         -20073,-20074,-20075,-20076,-20077,-20078,-20079,-20080,-20081,-20082,
         -20083,-20084,-20085,-20086,-20087,-20088,-20089,-20090,-20091,-20092,
         -20093,-20094,-20095,-20096,-20097,-20098,-20099)
         THEN
         INSTR_APO:=INSTR(DBMS_ERROR_TEXT_VAR,':',1)+1;
              INSTR_EOS:=INSTR(DBMS_ERROR_TEXT_VAR,'ORA-',2)-1;
              LENGTH_VAR:=INSTR_EOS-INSTR_APO;
                   DBMS_ERROR_TEXT_VAR:=SUBSTR(DBMS_ERROR_TEXT_VAR,INSTR_APO,LENGTH_VAR);
                   AL_ID:=FIND_ALERT('AL_STOP');
    SET_ALERT_PROPERTY(AL_ID,ALERT_MESSAGE_TEXT,DBMS_ERROR_TEXT_VAR);
    AL_N:=SHOW_ALERT(AL_ID);
         END IF;     

  • RAISE_APPLICATION_ERROR (which error_number?)

    Good morning,
    I am writing a function which should raise an application error if something doesnt work fine.
    The calling procedure should catch and handle this exception.
    CREATE FUNCTION f1 (value_1 IN VARCHAR2) RETURN INTEGER IS
    BEGIN
    IF something = 'wrong'
    THEN
    RAISE_APPLICATION_ERROR(-20000, 'something is wrong');
    END IF;
    END;
    CREATE PROCEDURE p1 (value_1 IN VARCHAR2) IS
    e_something_is_wrong EXCEPTION;
    PRAGMA EXCEPTION_INIT(e_something_is_wrong, -20000);
    BEGIN
    call f1;
    EXCEPTION
    WHEN e_something_is_wrong THEN
    do something;
    END;
    My Question No. 1 is:
    How can i assure that f1 is using an error_number which isnt used by any other called function in this procedure?
    No. 2:
    Is there a possibilty to force a calling procedure to handle possible errors raised of a called function like in JAVA?
    Many thanks in advance,
    André
    P.S.: Please feel free to ask further questions if you dont understand my questions, because english isnt my native language.

    You should use packages to get the easy and transparent control of
    your user defined exceptions, constants and so on:
    SQL> create or replace package my_pkg
      2  is
      3   my_exception_1 exception;
      4   my_exception_2 exception;
      5   pragma exception_init(my_exception_1,-20000);
      6   pragma exception_init(my_exception_2,-20001);
      7 
      8   procedure p1;
      9   procedure p2;
    10   procedure p3 (id number);
    11  end;
    12  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3   procedure p1
      4   is
      5   begin
      6    raise my_exception_1;
      7   end;
      8 
      9   procedure p2
    10   is
    11   begin
    12    raise my_exception_2;
    13   end;
    14 
    15   procedure p3(id number)
    16   is
    17   begin
    18    if id = 1 then p1; else p2; end if;
    19   exception
    20    when my_exception_1 or my_exception_2 then
    21     raise_application_error(sqlcode,'Exception number is ' || sqlcode);
    22    when others then
    23     raise;
    24   end;
    25  end;
    26  /
    Package body created.
    SQL> exec my_pkg.p3(1);
    BEGIN my_pkg.p3(1); END;
    ERROR at line 1:
    ORA-20000: Exception number is -20000
    ORA-06512: at "SCOTT.MY_PKG", line 21
    ORA-06512: at line 1
    SQL> exec my_pkg.p3(2);
    BEGIN my_pkg.p3(2); END;
    ERROR at line 1:
    ORA-20001: Exception number is -20001
    ORA-06512: at "SCOTT.MY_PKG", line 21
    ORA-06512: at line 1
    Rgds.

  • Printing Raise_application_error only for the first one..

    Hi, for each procedure i have a raise_application_error.. But after the first one, each one of the calling procedures print their applicaion error as well. How can I set this up so that only the raise_application_error from the function that's the exception is being raised from?
    Edited by: tolgaek on Jan 17, 2011 10:44 AM

    wonderboy87 wrote:
    Well actually, i'm printing the stack using DBMS_UTILITY.format_error_backtrace appended to my message using raise_application_error,Wrong.
    Therefore I don't need the other calling functions to print theirs,sometimes the stack is so deep that, error message gets cut off where you can't see the most important one.. I just want to make it so that only the first raise_application_error gets printed, which has enough information to debug..Wrong.
    You are mistaken in thinking that turning the error stack into an error text string is valid. A text string is unstructured data. An error stack is structured.
    And despite the fact that you can turn the error stack into a text error message, does not mean that the error stack no longer exists and no longer will be processed (and possibly displayed/printed) by the client that made the call.
    There's also a reason for having an error stack and having a separate error message. The former is for code, debuggers and developers to make sense of - this explains the exact status of the call stack at the time of the error. The latter is the nice-human-readable-message that is for end-users and managers and the like. This explains (or should) the business/logical reason of the error.
    It makes no sense to whack the error stack as text into the error message. What for? How does this make the exception any better to process or understand?

  • Raise_application_error and Write to Log

    Hi Gurus,
    I have scenario where I want to raise_application_error and also write that information to a log table. I am inserting into the log table first then raising the application error. The problem is that it never appears to write to the log unless I remove the raise_application_error. I am probably handling the process incorreclty, but I am not sure what I should do to get it to work.
    Any info would be greatly appreciated
    DB Version: 10g
    Note: This is handling exceptions that I encounter in a FORALL. I am using SAVE EXCEPTION.
    Example:
    EXCEPTION
    WHEN update_inventory_error THEN Call custom Exception Handler
    errors := SQL%BULK_EXCEPTIONS.COUNT; Count all of the Errors in the Bulk Collect
    FOR i IN 1..errors LOOP
    vErr := SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE);
    vDescrip:= 'Error #' || i || ' occurred during '|| 'ProductID: ' || l_amazon_sku(i) || ' iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
    Insert Into Feeds.FeedLog(ID,Feed,ErrorMessage,Description,ErrorDate)
    Values(
    Feeds.FeedLog_seq.nextval ID
    ,'Generate Inventory' FEED
    ,vErr ErrorMessage
    ,vDescrip Description
    ,SYSDATE);
    END LOOP;
    raise_application_error(-20101,'Generate Inventory Failed FORALL ISSUE');
    Edited by: ScarpacciOne on Jan 19, 2010 3:37 PM
    Edited by: ScarpacciOne on Jan 19, 2010 3:38 PM

    Thanks Tubby. I will look at Autonomous transactions and see what I can dig up. I will pull up my full Sproc and post it so folks can see what I am doing.
    --S                                                                                                                                                                                                                                                                                                                                       

  • Raise_application_error in after-logon-trigger

    Hi,
    I try to build a
    after logon on database trigger,
    this should execute some inserts into an audit-table, and if some conditions are not given, I want the user to be disconnected.
    In this forum I found this thread with a trigger similar to my needs:
    To prevent TOAD access
    But RAISE_APPLICATION_ERROR in this trigger does not cancel the session and so the user stays connected to oracle. Now I am searching for a disconnect-statement!
    Wolfram

    Wolfram,
    What we have here is
    - a post without a 4 digit database version. Most questions have a version specific answer. The behavior you describe does not apply to all versions, and might even apply to SYSDBA connected users only. Is everyone connecting as SYSDBA?
    - a post without a proper description of what the trigger does, and without a proper description of the business need. This is especially important as you seem to re-invent AUDIT CONNECT.
    - a post from someone who already thinks he knows the answer.
    Rest assured: there is no disconnect statement in PL/SQL
    You would really need to come up with more details
    - database version, 4 digits
    - the actual trigger code
    - what you are trying to accomplish in terms of business requirements
    - why you can't use AUDIT
    Sybrand Bakker
    Senior Oracle DBA

  • ProC: RAISE_APPLICATION_ERROR

    In procedure builder, I can use RAISE_APPLICATION_ERROR. However when I try to use it in ProC, my code will not compile. Why? Is there a work around?

    Try:
    EXEC SQL WHENEVER SQLERROR DO your_err_function();
    EXEC SQL WHENEVER SQLWARNING DO your_warning_function();

  • Trigger insert on 2nd table with raise_application_error ?

    Hi,
    Is it possible to use a raise_application_error IF you want an insert to fail on the table the insert trigger is based upon YET still allow an INSERT ON A SECOND TABLE ?
    Here is the trigger.
    CREATE OR REPLACE TRIGGER "SYSADM"."TBI_EARLY_RECEIPT_WARNING"
    BEFORE INSERT
    ON "RECEIVER_LINE" REFERENCING OLD AS OLDDATA NEW AS NEWDATA
    FOR EACH ROW
    DECLARE mDate SYSADM.PURC_ORDER_LINE.PROMISE_DATE%type;
    BEGIN
    SELECT
    SYSADM.PURC_ORDER_LINE.PROMISE_DATE
    INTO mDate
    FROM SYSADM.PURC_ORDER_LINE
    WHERE :NEWDATA.PURC_ORDER_LINE_NO = SYSADM.PURC_ORDER_LINE.LINE_NO
    AND :NEWDATA.PURC_ORDER_ID = SYSADM.PURC_ORDER_LINE.PURC_ORDER_ID;
    IF mDate > (SYSDATE + 30) THEN
              INSERT INTO BARCODERECEIVER_LINE
              (RECEIVER_ID, LINE_NO, PRINTED, QTY, PO, VENDOR, DESCRIPTION, PART, RECEIVED_DATE, PRINTER, EARLY, TRANSTIME)
              SELECT
         :NEWDATA.RECEIVER_ID,
         :NEWDATA.LINE_NO,
         'N',
         :NEWDATA.RECEIVED_QTY,
         :NEWDATA.PURC_ORDER_ID,
         SYSADM.VENDOR.NAME,
         SYSADM.PART.DESCRIPTION,
         NVL(SYSADM.PURC_ORDER_LINE.PART_ID, SYSADM.PURC_ORDER_LINE.VENDOR_PART_ID),
         SYSADM.RECEIVER.RECEIVED_DATE,
         DECODE(SYSADM.RECEIVER.USER_ID, 'CARL', 1, 'ORLANDO', 2, 'TONYA', 3, 'MATT', 'TOM', 3, 'SYSADM', 3),
    'Y',
    to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS')
         FROM SYSADM.RECEIVER, SYSADM.PURC_ORDER_LINE, SYSADM.PART, SYSADM.PURCHASE_ORDER, SYSADM.VENDOR
         WHERE :NEWDATA.RECEIVER_ID = SYSADM.RECEIVER.ID
         AND :NEWDATA.PURC_ORDER_LINE_NO = SYSADM.PURC_ORDER_LINE.LINE_NO
         AND :NEWDATA.PURC_ORDER_ID = SYSADM.PURC_ORDER_LINE.PURC_ORDER_ID
         AND SYSADM.PURC_ORDER_LINE.PART_ID = SYSADM.PART.ID (+)
         AND SYSADM.RECEIVER.PURC_ORDER_ID = SYSADM.PURCHASE_ORDER.ID (+)
         AND SYSADM.PURCHASE_ORDER.VENDOR_ID = SYSADM.VENDOR.ID (+)
         AND SYSADM.RECEIVER.USER_ID IN ('ORLANDO', 'TONYA', 'MATT', 'TOM', 'SYSADM');
    raise_application_error(-20000, 'Check with Purchasing please Exceeds Early Need Date');
    END IF;
    END;
    If you comment out the raise_error message insert on the second table works perfectly. Now we need to prevent the insert on the main table. Again the insert into BARCODERECEIVER_LINE should succeed but the insert on the RECEIVER_LINE table should fail. Is there any work-around for this ? Many thanks for any reply.
    Steve.

    Hello
    Here's an example of what you are trying to achieve(i think). I've not put any validation code in or anything but hopefully it demonstrates the principal...
    CREATE TABLE test_audit(PURC_ORDER_ID varchar2(20),
                         PURC_ORDER_LINE_NO NUMBER,
                         RECEIVER_ID varchar2(20),
                         LINE_NO varchar2(20),
                         PRINTED varchar2(20),
                         RECEIVED_QTY NUMBER,
                         PO varchar2(20),
                         VENDOR varchar2(20),
                         DESCRIPTION varchar2(20),
                         RECEIVED_DATE DATE) ;
    CREATE OR REPLACE PROCEDURE p_audit_insert(        v_PURC_ORDER_ID IN VARCHAR2,
                                                   v_PURC_ORDER_LINE_NO IN NUMBER,
                                                   v_RECEIVER_ID IN VARCHAR2,
                                                   v_LINE_NO IN VARCHAR2,
                                                   v_PRINTED IN VARCHAR2,
                                                   v_RECEIVED_QTY IN NUMBER,
                                                   v_PO IN VARCHAR2,
                                                   v_VENDOR IN VARCHAR2,
                                                   v_DESCRIPTION IN VARCHAR2,
                                                  v_RECEIVED_DATE IN DATE
       IS
          --Could be replaced with a function call to get the pipe name
          lv_PipeName     VARCHAR2(30) := 'Test_Audit_Pipe';
          ln_Status       NUMBER;
       BEGIN
          DBMS_PIPE.pack_message(v_PURC_ORDER_ID );
          DBMS_PIPE.pack_message(v_PURC_ORDER_LINE_NO );
          DBMS_PIPE.pack_message(v_RECEIVER_ID );
          DBMS_PIPE.pack_message(v_LINE_NO );
          DBMS_PIPE.pack_message(v_PRINTED );
          DBMS_PIPE.pack_message(v_RECEIVED_QTY );
          DBMS_PIPE.pack_message(v_PO );
          DBMS_PIPE.pack_message(v_VENDOR );
          DBMS_PIPE.pack_message(v_DESCRIPTION );
          DBMS_PIPE.pack_message(v_RECEIVED_DATE );
          ln_Status := DBMS_PIPE.send_Message(lv_PipeName);
         dbms_output.put_line(ln_Status);
       END;
    CREATE TABLE test_table(text       varchar2(20));
    CREATE OR REPLACE TRIGGER test_table_trigger BEFORE INSERT ON test_table
    FOR EACH ROW
    DECLARE
    BEGIN
       IF :NEW.text = 'Create audit row' THEN
               p_audit_insert( 'Purch order',
                               123,
                               'Receiver id',
                               'Line no',
                               'Printed',
                               456,
                               'PO number',
                               'Vendor',
                               :NEW.Text,
                               SYSDATE
               RAISE_APPLICATION_ERROR(-20001,'Audit row generated');
       END IF;
    END;
    CREATE OR REPLACE PROCEDURE p_Read_Audit_Pipe
    IS
       lv_PipeName     VARCHAR2(30) := 'Test_Audit_Pipe';
       ln_Status       NUMBER;
       ln_DataType     NUMBER;
       ln_NumData      NUMBER;
       lv_CharData     VARCHAR2(32767);
       ldt_DateData    DATE;
       lv_PURC_ORDER_ID        VARCHAR2(20);
       lv_PURC_ORDER_LINE_NO   NUMBER;
       lv_RECEIVER_ID          VARCHAR2(20);
       lv_LINE_NO              VARCHAR2(20);
       lv_PRINTED              VARCHAR2(20);
       lv_RECEIVED_QTY         NUMBER;
       lv_PO                   VARCHAR2(20);
       lv_VENDOR               VARCHAR2(20);
       lv_DESCRIPTION          VARCHAR2(20);
       lv_RECEIVED_DATE        DATE;
    BEGIN
       ln_Status := dbms_pipe.receive_message(lv_PipeName);
       dbms_pipe.unpack_message(lv_PURC_ORDER_ID);
       dbms_pipe.unpack_message(lv_PURC_ORDER_LINE_NO);
       dbms_pipe.unpack_message(lv_RECEIVER_ID);
       dbms_pipe.unpack_message(lv_LINE_NO);
       dbms_pipe.unpack_message(lv_PRINTED);
       dbms_pipe.unpack_message(lv_RECEIVED_QTY);
       dbms_pipe.unpack_message(lv_PO);
       dbms_pipe.unpack_message(lv_VENDOR);
       dbms_pipe.unpack_message(lv_DESCRIPTION);
       dbms_pipe.unpack_message(lv_RECEIVED_DATE);
       INSERT
       INTO
               test_audit
       VALUES( lv_PURC_ORDER_ID,
               lv_PURC_ORDER_LINE_NO,
               lv_RECEIVER_ID,
               lv_LINE_NO,
               lv_PRINTED,
               lv_RECEIVED_QTY,
               lv_PO,
               lv_VENDOR,
               lv_DESCRIPTION,
               lv_RECEIVED_DATE
       COMMIT;
    END;
    SQL> insert into test_table values('Test table row');
    1 row created.
    SQL> insert into test_table values('Create audit row');
    insert into test_table values('Create audit row')
    ERROR at line 1:
    ORA-20001: Audit row generated
    ORA-06512: at "TEST.TEST_TABLE_TRIGGER", line 19
    ORA-04088: error during execution of trigger 'TEST.TEST_TABLE_TRIGGER'
    --This bit is done in another session
    SQL> exec p_Read_Audit_Pipe;
    SQL> select * from test_audit;
    Purch order   123 Receiver id    Line no   456   PO Number Vendor   Create audit row    06/09/2004
    SQL> select * from test_table;
    TEXT
    Test table row

Maybe you are looking for