Pragma exception_init

HI,
I want log the ORA-00942 error through exception.
declare
v_no number;
v_error exception;
pragma exception_init(v_error,-942);
begin
select empno into v_no from notable;
exception
when v_error then
insert into log values('no table');
end;
when ever i execute the program ,instead of logging error in log table ..it is raising error that ' ORA-942 TABLE OR VIEW DOESN'T EXIST'. i want log this message in logtable instead of raising error
Thanks

Hi,
only a short addition/illustration to/of the idea provided by SY
-- Create Log-Table
drop table log;
Create table log ( msg varchar2(4000 char));
drop table notable;
-- P compiles without table "NOTABLE" because of the use of dynamic sql see
-- Solomon Yakobsons post above
create or replace
procedure p
as
     v_no number;
     v_stmt varchar2(2000) := 'select empno from notable';
     v_error exception;
     pragma exception_init(v_error,-942);
begin
     EXECUTE IMMEDIATE v_stmt into v_no;
     insert into log values('j = '|| (nvl(to_char(v_no), '<<NULL>>')));
exception
when v_error then
     insert into log values('no table');
        -- you somehow need the following commit to make the changes in the log-table permanent;
        -- other way could be combining this method with autonomous transactions
     commit;
when others then
     insert into log values(substr(dbms_utility.format_error_stack,1,4000));
        -- commit; /*????*/
end;
-- 1. table "NOTABLE" doesn't exist => "no table" in log-table
truncate table log;
exec p;
select * from log;
-- 2. table "NOTABLE" exists but is empty => "ORA-01403: no data found"
create table notable (empno Number);
truncate table log;
-- writes log-message "ORA-01403: no data found" into log-table
exec p;
select * from log;
-- 3. one row in "NOTABLE"; "all is well"; here "j = 1"
-- insert first row into notable
insert into notable (empno) values (1);
commit; -- not needed because of the following truncate
-- writes value of the selection into the log-table
truncate table log;
exec p;
select * from log;
-- 4. two rows in notable => "ORA-01422: exact fetch returns more than requested number of rows"
-- insert second row
insert into notable (empno) values (2);
commit;
truncate table log;
-- writes error
exec p;
select * from log;So the "COMMIT" in the exception-handler may cause some trouble, if you just write without commiting here,
a calling stored procedure might rollback your changes, which will be very misleading. The use of AUTONOMOUS TRANSACTIONS
could get complicated too, please be careful here.
See [url http://tkyte.blogspot.de/search?q=autonomous+transactions] Tom Kyte Blog about AUTONOMOUS TRANSACTIONS, EXCEPTION WHEN OTHERS, ... why and when autonomous transactions can help you and if you should rethink your strategy about not reraising the error. Your business logic is broken in this case, isn't it? So why carry on?
Regards
stratmo
PS: User Profile for 920033     Handle:     920033
Status Level:     Newbie
Registered:     Mar 10, 2012
Total Posts:     52
Total Questions:     20 (20 unresolved)
>
Uuuups, seems that there is some work to do for you;-)

Similar Messages

  • How attend error in forms menu like pragma exception_init ?

    hello,
    I have problem with error in my menu. I created menu and I put code to my buttons in menu:for example execute_trigger('test');
    I have some forms and if I am in another forms and call my button with execute_trigger('test');
    I get error FRM-40700: No such trigger: test
    Its ok because I have trigger in another block. But how to attend this error. I put pragma execption_init but not work
    declare
    text exception;
    pragme exception_init(text,-40700);
    begin
    execute_trigger('test');
    exception
    when text then
    message('its work');
    end;
    I create code like this in menu;
    execute_trigger('test');
    if form_failure then
    message('its work');
    end if;
    end;
    and this work but I get error FRM-40700: No such trigger: test and next message is 'its work'. How to turn off message from forms?? or like this message make like pragma...
    regards

    thanks for reply.
    trigger exist but in another block.
    I check system.message-level
    thanks
    I find another solution
    I put procedure which verificate current_block and current_form and then call execute_trigger(). It's work
    Edited by: user515960 on 2010-07-18 02:43

  • Priority of pragma exception_init..

    Hi All,
    Suppose I am using pragma exception_init for NO_DATA_FOUND error,
    and the variable I am using is "test_excp" in my stored procedure, in the exception section if I am using both the user defined exception and the system defined exception (i.e. when test_excp then and when NO_DATA_FOUND then ) then which exception will the engine pick?
    This is not a business requirement but its a doubt on my part.
    Please help me understanding this concept..
    Thanks in advance!!
    Bits

    Confused yet?
    Note that there is also a -100 no data found error in Oracle but it appears to be treated as an entirely separate exception (albeit with the same message), e.g.
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> DECLARE
      2     e_no_data_found EXCEPTION;
      3     PRAGMA EXCEPTION_INIT (e_no_data_found, -100);
      4  BEGIN
      5     RAISE e_no_data_found;
      6  EXCEPTION
      7     WHEN NO_DATA_FOUND THEN
      8        RAISE_APPLICATION_ERROR (-20000, 'encountered NO_DATA_FOUND exception.', TRUE);
      9     WHEN e_no_data_found THEN
    10        RAISE_APPLICATION_ERROR (-20000, 'encountered e_no_data_found exception.', TRUE);
    11  END;
    12  /
    DECLARE
    ERROR at line 1:
    ORA-20000: encountered e_no_data_found exception.
    ORA-06512: at line 10
    ORA-00100: no data found
    SQL>

  • Pragma Exception_INIT- Doubt

    Hi All
    Why we are using 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 above code i get
    PL/SQL procedure successfully completed. ORA-1400 occurred
    The same code when i try to give error message is ORA-1500 occurred
    I get
    ORA-01400: cannot insert NULL into ("XXI"."EMPLOYEES"."EMPLOYEE_ID")
    ORA-06512: at line 6
    why it happens?
    And when i use 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 of and usage for Pragma Exception_INIT
    Thank in advance
    Suresh

    You must to issue:
    SET SERVEROUTPUT ONto tell SQL*PLus to display DBMS_OUTPUT buffer:
    SQL> Declare    
      2        e_MissingNull EXCEPTION;
      3       PRAGMA EXCEPTION_INIT(e_MissingNull, -1400);
      4  BEGIN
      5       INSERT INTO Employees (employee_id) VALUES (NULL);
      6  EXCEPTION
      7       WHEN e_MissingNull then
      8          DBMS_OUTPUT.put_line('ORA-1400 occurred');
      9  END;
    10  /
    PL/SQL procedure successfully completed.
    SQL> SET SERVEROUTPUT ON
    SQL> Declare    
      2        e_MissingNull EXCEPTION;
      3       PRAGMA EXCEPTION_INIT(e_MissingNull, -1400);
      4  BEGIN
      5       INSERT INTO Employees (employee_id) VALUES (NULL);
      6  EXCEPTION
      7       WHEN e_MissingNull then
      8          DBMS_OUTPUT.put_line('ORA-1400 occurred');
      9  END;
    10  /
    ORA-1400 occurred
    PL/SQL procedure successfully completed.
    SQL> Now about zero_divide. You are initializing exception e_sample with -5737, while zero_divide is -1476:
    SQL> Declare
      2         I Number;
      3        e_sample EXCEPTION;
      4       PRAGMA EXCEPTION_INIT(e_sample, -1476);
      5  BEGIN
      6       select 1/0 Into I From Dual ; -- I know Zero_Divide Error i thought the changing this error in my style
      7  EXCEPTION
      8       WHEN e_sample then
      9          DBMS_OUTPUT.put_line('ORA-5737 Not valid');
    10  END;
    11  /
    ORA-5737 Not valid
    PL/SQL procedure successfully completed.
    SQL> SY.

  • PRAGMA EXCEPTION_INIT (bulk_errors, -24381);

    PRAGMA EXCEPTION_INIT (bulk_errors, -24381);
    Can u plz explain me what is use of this statement if I declare like this. And also tell me use of the PRAGMA

    In PL/SQL, sometimes it becomes necessary to raise a predefined Oracle error
    as an exception. Depending on the error number, there are some predefined
    EXCEPTIONs that can be raised. These EXCEPTIONs are defined in package
    STANDARD and are globally available. Other errors do not have predefined
    EXCEPTIONs declared. In order to associate a predefined error number to an
    EXCEPTION, use the PRAGMA EXCEPTION_INIT. When using PRAGMA EXCEPTION_INIT,
    remember that all Oracle error numbers with exception of 1403 and 100 are
    negative.
    Once the EXCEPTION has been aliased, the EXCEPTION can then be raised.

  • Srw package throwing PRAGMA exception_init(SPECIFY_PROTOCOL, -20002)

    I've added srw.ADD_PARAMETER ( plRepParam, 'server_protocol', 'HTTP/1.1' ); to no avail. Any ideas?

    Twas muppetry on my part, I had missed http:// from my gateway param setting.

  • PRAGMA forcing integral number

    The following line of code won't compile,
              PRAGMA EXCEPTION_INIT(XCPT_invalid_param, ERR_invalid_fax_code);however, this will:
              PRAGMA EXCEPTION_INIT(XCPT_invalid_param, -20001);ERR_invalid_fax_code is declared as
              ERR_invalid_fax_code           CONSTANT INTEGER := -20001;What to I do to make it accept a constant var, instead of an integral number?

    The second argument to EXCEPTION_INIT must be a literal.
    I don't know why, that's just the way it is.
    See:
    http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96525/pcmus.htm#1001616

  • Differnce between exception_init and init_exception

    I have declared an usernamed exception and wanted to call...
    I came to know that these can be called by using two of the below -
    Pragma Exception_init
    Pragma Init_Exception
    What is the differnce between[b] exception_init and init_exception ? And where they can be used ?
    awating for your rresponse ..!

    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0:
    SQL>declare
      2     my_exception exception;
      3     pragma exception_init(my_exception, -20101);
      4  begin
      5     raise my_exception;
      6  exception
      7     when my_exception then
      8        dbms_output.put_line(sqlerrm);
      9  end;
    10  /
    ORA-20101:
    PL/SQL procedure successfully completed.
    SQL>declare
      2     my_exception exception;
      3     pragma init_exception(my_exception, -20101);
      4  begin
      5     raise my_exception;
      6  exception
      7     when my_exception then
      8        dbms_output.put_line(sqlerrm);
      9  end;
    10  /
       pragma init_exception(my_exception, -20101);
    ERROR at line 3:
    ORA-06550: line 3, column 11:
    PLS-00127: Pragma INIT_EXCEPTION is not a supported pragma

  • PRAGMA EXCEPTION

    Morning,
    Would some one please review this code below? I am trying to capture the oracle error table or view does not exist -00942 but it does not seem to want to work. What am I typing wrong?? It throws the error instead of it being handle within the exception section. This table is not available when I run it in 9i.
    I simplified the select statement.
    declare
    table_view_not_exist EXCEPTION;
    PRAGMA EXCEPTION_INIT(table_view_not_exist, -00942);
    begin
    select end_time from dba_optstat_operations;
    EXCEPTION
    WHEN table_view_not_exist
    THEN
    DBMS_OUTPUT.PUT_LINE('PLEASE RUN ANALYZE MANUALLY');
    end;
    Any help in this matter would be appreciated.
    Thanks in advance and have a great day.
    al

    The code cannot compile if the table isn't present.
    Try this:
    DECLARE
         table_view_not_exist EXCEPTION;
         PRAGMA EXCEPTION_INIT(table_view_not_exist, -942);
            v_end_time DATE;
    BEGIN
         EXECUTE IMMEDIATE 'SELECT end_time FROM dba_optstat_operations'
            INTO v_end_time;
            DBMS_OUTPUT.PUT_LINE('End date: ' || TO_CHAR(v_end_time,'YYYY-MM-DD HH24:MI:SS'));
    EXCEPTION
         WHEN table_view_not_exist THEN
              dbms_output.put_line('Please run analyze manually');
    END;

  • Trapping in APForm Trig via PRAGMA EXCEPTION

    hi,
    I can trap 06052 errors in report 6i (After pform trig)
    but not -01843,-01847 and a few others relating to date format input mask errors. Anyone know why?
    Thanks.
    N.
    Here's how I do it: (in after pform trig)
    date_invalid EXCEPTION;
    PRAGMA EXCEPTION_INIT (date_invalid, -01843);
    BEGIN
    EXCEPTION
    when date_invalid THEN srw.message('Date must in Format ''DD-MON-YYYY'' !');
    RETURN ( FALSE );
    END;

    .

  • Error while creating a procedure (PLS-00103)

    Hi Am create the follwing Procedure:-
    create or replace PROCEDURE XL_SP_ROGUEUSERS (
    csrresultset_inout IN OUT sys_refcursor,
    intuserkey_in IN NUMBER,
    strsortcolumn_in IN VARCHAR2,
    strsortorder_in IN VARCHAR2,
    intstartrow_in IN NUMBER,
    intpagesize_in IN NUMBER,
    intdocount_in IN NUMBER,
    inttotalrows_out OUT NUMBER,
    strfiltercolumnlist_in IN VARCHAR2,
    strfiltercolumnvaluelist_in IN VARCHAR2,
    strudfcolumnlist_in IN VARCHAR2,
    strudfcolumnvaluelist_in IN VARCHAR2,
    struserlogin_in IN VARCHAR2,
    strfirstname_in IN VARCHAR2,
    strlastname_in IN VARCHAR2,
    strdate_in IN VARCHAR2
    AS
    BEGIN
    DECLARE
    whereclause VARCHAR2(8000);
    select_stmt VARCHAR2(8000);
    strColumnList VARCHAR2(4000);
    strDateFormat VARCHAR2 (80);
    strFromClause VARCHAR2(4000);
    strWhereClause VARCHAR2(4000);
    strOrderByClause VARCHAR2(2000);
    intSortDirection_in PLS_INTEGER;
    entsum     varchar2(20) := 'Entitlements Summary';
    str_row EXCEPTION;
    do_cnt EXCEPTION;
    no_logged_in_user EXCEPTION;     
    property_not_found EXCEPTION;
    pragma exception_init(Str_row,-20001);
    pragma exception_init(Do_cnt,-20002);
    pragma exception_init(no_logged_in_user,-20003);     
    BEGIN
    -- Throw exception if the start row or page size is either NULL or have
    -- values less than or equal to zero
    IF (intstartrow_in <= 0 OR intpagesize_in <= 0 OR intstartrow_in IS NULL OR intpagesize_in IS NULL)
         THEN
         RAISE str_row;
    END IF;
    -- Throw exception if the intdocount_in parameter is NULL or has a value
    -- other than 0 and 1
    IF intdocount_in NOT IN (0, 1, 2) OR intdocount_in IS NULL
         THEN
         RAISE do_cnt;
    END IF;
    -- Throw exception if the intuserkey_in (logged in user) parameter is NULL
    IF intuserkey_in IS NULL or intuserkey_in <= 0
         THEN
         RAISE no_logged_in_user;
    END IF;
    -- Now, we start accumulating the whereclause based on the input
    -- parameters, performing error checking along the way.
    --Organization Permissioning.
    /* whereclause := ' and usr.act_key IN (SELECT DISTINCT act2.act_key FROM '||
    ' act act2, aad, usg, ugp, usr usr5 '||
    ' WHERE act2.act_key = aad.act_key '||
    ' and aad.ugp_key = usg.ugp_key '||
    ' and ugp.ugp_key = usg.ugp_key'||
    ' and usg.usr_key = usr5.usr_key'||
    ' and usr5.usr_key = '||intuserkey_in||')'; */
    IF strfiltercolumnlist_in IS NOT NULL AND
    strfiltercolumnvaluelist_in IS NOT NULL THEN
    whereclause := whereclause
    || xl_sfg_parseparams(strfiltercolumnlist_in,
    strfiltercolumnvaluelist_in);
    END IF;
    IF struserlogin_in IS NOT NULL THEN
    whereclause := whereclause
    || ' AND UPPER(usr.usr_login) LIKE '
    || UPPER (''''||struserlogin_in||'''')
    || ' ';
    END IF;
    IF strudfcolumnlist_in IS NOT NULL AND
    strudfcolumnvaluelist_in IS NOT NULL THEN
    whereclause := whereclause
    || xl_sfg_parseparams(strudfcolumnlist_in,
    strudfcolumnvaluelist_in);
    END IF;
    -- Perform the count query and store the result in inttotalrows_out
         inttotalrows_out := 0;
    IF intdocount_in IN (1,2) THEN
    EXECUTE IMMEDIATE ' select count(*) from((SELECT upper(rcd.RCD_VALUE) as "User ID" '||                                        ' FROM rce, obj, rcd, orf '||
                   ' WHERE '||
                   ' RCE_STATUS like 'No Match Found' '||
                   ' AND ((orf.ORF_FIELDNAME like 'User ID') or (orf.ORF_FIELDNAME like 'User%Login')) '||
                   ' AND rce.OBJ_KEY = obj.OBJ_KEY '||
                   ' AND rce.RCE_KEY = rcd.RCE_KEY '||
                   ' AND rcd.ORF_KEY = orf.ORF_KEY '||
                   ' ) '||
                   ' MINUS '||
                   ' (SELECT usr.USR_LOGIN FROM usr '||
                   ' WHERE '||
                   ' usr.USR_STATUS like 'Active')) '||
                   whereclause INTO inttotalrows_out;
    -- UI needs the SP to return result set always. The following is returned
    -- when the indocount is 2 which does not return any result set but count
    IF intdocount_in = 2 THEN
    select_stmt := 'SELECT ''dummy'' FROM dual';
    OPEN csrresultset_inout FOR select_stmt;          
    END IF;
    END IF;
    -- If intdocount_in is 2, UI just wants to get the totalrows to give
    -- the warning to users if the result set exceeds the limit set by
    -- UI. When ntdocount_in is 2, the following block won't be executed.
    IF intdocount_in IN (0,1) THEN          
    -- Construct the select query by calling XL_SPG_GetPagingSql.
    -- This is the main query for this stored procedure
    strOrderByClause := ' usr.usr_login';
    --strOrderByClause := ' req.req_key';
    IF strsortorder_in = 'DESC' THEN
    intSortDirection_in := 0;
    ELSE
    intSortDirection_in := 1;          
    END IF;
    XL_SPG_GetPagingSql(strColumnList,
    strFromClause,
    whereclause,
    strOrderByClause,
    intSortDirection_in,
    intStartRow_in,
    intPageSize_in,
    select_stmt
    OPEN csrresultset_inout FOR select_stmt;
    END IF;     
    -- Exception Handling
    EXCEPTION
    WHEN Str_row THEN
    RAISE_APPLICATION_ERROR(sqlcode,
    'Start Row/Page Size cannot be NULL OR less than or equal to zero ');
    WHEN Do_cnt THEN
    RAISE_APPLICATION_ERROR(sqlcode,
    'Do Count must be 0, 1 or 2. ');
    WHEN no_logged_in_user THEN
    RAISE_APPLICATION_ERROR(sqlcode,
    'Logged-in User Key cannot be NULL OR less than or equal to zero ');
    END;
    end XL_SP_ROGUEUSERS;
    But Am getting the following error message, I couldn't figure wat it is.Can anyone help me:-
    PLS-00103: Encountered the symbol "NO" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem return returning <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between into using || bulk member SUBMULTISET_

    Please use tags when posting code. Also please format the code so that blocks line up vertically - often that makes syntax errors like missing END IFs etc much easier to spot.                                                                                                                                                                                                                                                                                                                                                                           

  • Want to convert function in SQL Server 2000

    Hi ,
    i am writing this function in oracle.Could you please convert this function in SQL Server 2000 because i am new in this and dont know how to use decode function in sql.
    Please following is the code for oracle.
    CREATE OR REPLACE function fun ( localex varchar2,titlex varchar2)
    return number
    as  x number;
    begin
    select sum ( decode (count (username),max(prereq_count),1,0) ) x into x from
       SELECT
                       prereq_count,
                       username
                 FROM
                         table1
    group by     username ;
    return x;
    end fun;
    Regards
    Vishal

    Just take a look example below might give you idea :
    create or replace function f_makeAddress_tx (
    i_address_tx VARCHAR2,
    i_city_tx VARCHAR2,
    i_state_tx VARCHAR2,
    i_zip_tx VARCHAR2)
    return VARCHAR2
    is
    e_badZip EXCEPTION; u279E8
    pragma EXCEPTION_init(e_badZip,-20998); u279E9
    v_out_tx VARCHAR2(256);
    begin
    p_validateZip (i_zip_tx); u279E12
    v_out_tx:= i_address_tx||u2019, u2018|| u279E13
    i_city_tx ||u2019, u2018||
    i_state_tx ||u2019, u2018||
    i_zip_tx;
    return v_out_tx; u279E17
    exception
    when e_badZip then u279E19
    return i_zip_tx || u2018: Invalid zip code.u2019;
    end;
    Regards,
    Clint

  • Using user-defined data types in Forms 6i

    When I use the following code in Oracle Forms 6i
    PROCEDURE test IS
    prcl prcl_ty;
    BEGIN
    prcl := prcl.setParcel('xxx-xx-xxxx');
    END;
    I get 'Error 801'. However the above does work in SQL editor. The online help says PL/SQL8 client-side program units cannot support Oracle 8 object-related functionality and I suspect this is the reason I get the error from Forms. Is there a work-around for this.
    The TYPE is defined as:
    CREATE OR REPLACE
    TYPE PRCL_TY AS OBJECT
    (parcel VARCHAR2(11),
    MEMBER FUNCTION getBook RETURN VARCHAR2,
    MEMBER FUNCTION getMap RETURN VARCHAR2,
    MEMBER FUNCTION getItem RETURN VARCHAR2,
    MEMBER FUNCTION getItem_NS RETURN VARCHAR2,
    MEMBER FUNCTION getSplit      RETURN VARCHAR2,
    MEMBER FUNCTION find RETURN VARCHAR2,
    MEMBER FUNCTION find (yr in VARCHAR2) RETURN VARCHAR2,
    MEMBER FUNCTION isValid RETURN BOOLEAN,
    MEMBER FUNCTION toString                     RETURN VARCHAR2,
    MEMBER FUNCTION toString (par IN VARCHAR2) RETURN VARCHAR2,
    STATIC FUNCTION setParcel (istr IN VARCHAR2 DEFAULT '000-00-000A') RETURN prcl_ty) -- to be used as a constructor
    NOT FINAL
    CREATE OR REPLACE
    TYPE BODY PRCL_TY AS
    MEMBER FUNCTION getBook RETURN VARCHAR2 IS
    BEGIN
    return substr(self.parcel,1,3);
    END;
    MEMBER FUNCTION getMap RETURN VARCHAR2 IS
    BEGIN
    return substr(self.parcel,4,2);
    END;
    MEMBER FUNCTION getItem RETURN VARCHAR2 IS
    BEGIN
    return substr(self.parcel,6);
    END;
    MEMBER FUNCTION getItem_NS RETURN VARCHAR2 IS
    BEGIN
    return substr(self.parcel,6,3);
    END;
    MEMBER FUNCTION getSplit RETURN VARCHAR2 IS
    BEGIN
    return substr(self.parcel,9,1);
    END;
    MEMBER FUNCTION find RETURN VARCHAR2 IS
    found varchar2(1);
    BEGIN
    begin
    select 'x'
         into found
         from casrp
         where cp_book_num = self.getBook
         and cp_map_num = self.getMap
         and cp_item_num = self.getItem
              and rownum = 1;
         return 'CASRP';
         exception
         when NO_DATA_FOUND then
         begin
    select 'x'
         into found
         from pro_prop
         where pp_book_num = self.getBook
         and pp_map_num = self.getMap
         and pp_item_num = self.getItem
              and rownum = 1
              and NOT EXISTS (select 'x'
                                  from cncl_prcl
                                  where cr_book_num = self.getBook
                                  and cr_book_num = self.getMap
                                       and cr_book_num = self.getItem
                                       and rownum = 1);
         return 'PRO_PROP';
         exception
         when NO_DATA_FOUND then
              return '';
         end;
    end;
    END;
    MEMBER FUNCTION find (yr IN VARCHAR2) RETURN VARCHAR2 IS
    found varchar2(1);
    BEGIN
    begin
    select 'x'
         into found
         from casrp
         where cp_book_num = self.getBook
         and cp_map_num = self.getMap
         and cp_item_num = self.getItem
              and cp_tax_yr = yr
              and rownum = 1;
         return 'CASRP';
         exception
         when NO_DATA_FOUND then
         begin
    select 'x'
         into found
         from pro_prop
         where pp_book_num = self.getBook
         and pp_map_num = self.getMap
         and pp_item_num = self.getItem
              and pp_tax_yr = yr
              and rownum = 1
              and NOT EXISTS (select 'x'
                                  from cncl_prcl
                                  where cr_book_num = self.getBook
                                  and cr_book_num = self.getMap
                                       and cr_book_num = self.getItem
                                       and cr_tax_yr = yr
                                       and rownum = 1);
         return 'PRO_PROP';
         exception
         when NO_DATA_FOUND then
              return '';
         end;
    end;
    END;
    MEMBER FUNCTION isValid RETURN BOOLEAN IS
    i number;
    BEGIN
    for i in 1..8 loop
         if substr(parcel,i,1) not between '0' and '9' then
         return FALSE;
         end if;
         end loop;
         if nvl(substr(parcel,9,1),'#') not between 'A' and 'Z' and
         nvl(substr(parcel,9,1),'#') != '#' then
         return FALSE;
         end if;
         return TRUE;
    END;
    MEMBER FUNCTION toString RETURN VARCHAR2 IS
    BEGIN
    return self.toString('-');
    END;
    MEMBER FUNCTION toString (par IN VARCHAR2) RETURN VARCHAR2 IS
    BEGIN
    return self.getBook||par|| self.getMap||par|| self.getItem;
    END;
    STATIC FUNCTION setParcel (istr IN VARCHAR2 DEFAULT '000-00-000A') RETURN prcl_ty IS
    len number;
    pos number;
         lastch varchar2(1);
    temp varchar2(30);
    invalid_format exception;
         pragma exception_init(invalid_format,-9001);
    BEGIN
    temp := upper(istr);
    -- Find 1st occurance of '-'. If not in correct postion, pad book num with zeros.
         pos := instr(temp,'-',1,1);
    if pos > 0 then
         if pos != 4 then
    temp := lpad(substr(temp,1,pos-1),3,'0')||substr(temp,pos);
         end if;
    -- Find 2nd occurance of '-'. If not in correct postion, pad map num with zeros.
         pos := instr(temp,'-',1,2);
         if pos != 7 then
    temp := substr(temp,1,4)||lpad(substr(temp,5,1),2,'0')||substr(temp,pos);
         end if;
         -- Pad item num
         len := length(temp);
         lastch := substr(temp,len);
         temp := substr(temp,1,7)||lpad(substr(temp,8,len-1),3,'0');
         if lastch between 'A' and 'Z' then
              temp := temp||lastch;
         end if;
    end if;
    temp := replace(temp,'-','');
         if prcl_ty(temp).isValid then
    return (prcl_ty(temp));
         else
         raise invalid_format;
         end if;
    END;
    END;
    Rich Hall
    [email protected]

    You are correct in your assumptions. Client side PLSQL does not support user defined types like the one you are trying to use.
    There are no workarounds I am afraid.

  • How to find the table name on which integrity constraint not found

    Hi All
    How to acheive this
    I have a lot of tables with lot of primary key - foreign key
    relationship.
    In plsql
    when any inserts happen in the child table & the corresponding row is not present in the parent table, we get an exception
    ORA-02291: integrity constraint (user1.ppk) violated - parent key not found
    On this exception , in the exception block i want to trap teh name of the parent table on which the primary key for the particular child table was not there
    Is it possible to retrieve the parent table in this way. I am looking for a generic plsql code block which can help to acheive this
    Regards

    scott@ORA92> SET SERVEROUTPUT ON
    scott@ORA92> DECLARE
      2    e_no_parent_key EXCEPTION;
      3    PRAGMA            EXCEPTION_INIT (e_no_parent_key, -2291);
      4    v_fk_cons       VARCHAR2 (61);
      5    v_owner            VARCHAR2 (30);
      6    v_parent_table  VARCHAR2 (61);
      7    v_pk_cons       VARCHAR2 (30);
      8    v_parent_column VARCHAR2 (30);
      9  BEGIN
    10    INSERT INTO emp (empno, deptno) VALUES (99, 60);
    11  EXCEPTION
    12    WHEN e_no_parent_key THEN
    13        -- extract schema.constraint_name from sqlerrm:
    14        v_fk_cons:= SUBSTR (SQLERRM,
    15                      INSTR (SQLERRM, '(') + 1,
    16                      INSTR (SQLERRM, ')') - (INSTR (SQLERRM, '(') + 1));
    17        DBMS_OUTPUT.PUT_LINE ('Foreign key constraint violated: ' || v_fk_cons);
    18        -- extract parent schema.table and parent key:
    19        SELECT owner, table_name, constraint_name
    20        INTO     v_owner, v_parent_table, v_pk_cons
    21        FROM     user_constraints
    22        WHERE     (owner, constraint_name) =
    23            (SELECT r_owner, r_constraint_name
    24             FROM     user_constraints
    25             WHERE     owner || '.' || constraint_name = v_fk_cons);
    26        DBMS_OUTPUT.PUT_LINE ('Parent table: ' || v_owner || '.' || v_parent_table);
    27        DBMS_OUTPUT.PUT_LINE ('Parent key: ' || v_owner || '.' || v_pk_cons);
    28        -- extract parent table columns:
    29        FOR rec IN
    30          (SELECT column_name
    31           FROM   user_cons_columns
    32           WHERE  owner = v_owner
    33           AND    table_name = v_parent_table
    34           AND    constraint_name = v_pk_cons)
    35        LOOP
    36          DBMS_OUTPUT.PUT_LINE
    37            ('Parent table column: ' || rec.column_name);
    38        END LOOP;
    39  END;
    40  /
    Foreign key constraint violated: SCOTT.FK_DEPTNO
    Parent table: SCOTT.DEPT
    Parent key: SCOTT.PK_DEPT
    Parent table column: DEPTNO
    PL/SQL procedure successfully completed.

  • Drop table if exists in sql statement

    Oracle: 10G
    Is there a way to check if table exist and then only drop table. Something like:
    drop table (select table_name from user_tables where lower(table_name) = 'o2i_filing_dest')

    As already suggested, you could e.g. use an anonymous PL/SQL block as part of your SQL script, e.g. something like that:
    set echo on
    spool <your_log_file>
    WHENEVER SQLERROR EXIT FAILURE
    DECLARE
      PROCEDURE EXEC_DONT_FAIL( P_CMD IN VARCHAR2 ) IS
        e_table_or_view_does_not_exist exception;
        pragma exception_init(e_table_or_view_does_not_exist, -942);
        e_type_does_not_exist exception;
        pragma exception_init(e_type_does_not_exist, -4043);
        e_sequence_does_not_exist exception;
        pragma exception_init(e_sequence_does_not_exist, -2289);
      BEGIN
        EXECUTE IMMEDIATE P_CMD;
      EXCEPTION
      WHEN e_table_or_view_does_not_exist OR e_type_does_not_exist OR e_sequence_does_not_exist THEN
          NULL;
      END;
    BEGIN
      EXEC_DONT_FAIL('drop type <type_name1> force');
      EXEC_DONT_FAIL('drop view <view_name1>');
      EXEC_DONT_FAIL('drop table <table_name1> purge');
      EXEC_DONT_FAIL('drop sequence <seq_name1>');
    END;
    CREATE TABLE ...Note that the literals in angle brackets are just placeholders for demonstration purposes, you need to use your actual object names/file names there.
    Of course you could also use a FOR ... LOOP in the PL/SQL block that queries e.g. USER_OBJECTS to find out which objects to drop.
    That way it is ensured that only expected exceptions will be ignored but all others will raise and stop your script in that case.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/
    Edited by: Randolf Geist on Sep 25, 2008 10:09 AM
    Clarification regarding angle brackets added

Maybe you are looking for