When Others not raised for Dynamic SQL occasionally

Hi All,
Please consider some part of my PL/SQL code below.
FOR rec IN cur_job_steps
LOOP
update_job_step_status(p_sector,
p_job_name,
rec.step_name,
'Running',
NULL,
SYSDATE,
NULL
-- Execute Job Step Function
EXECUTE IMMEDIATE 'BEGIN ' || rec.step_function || '; END;';
-- Set Job Step End Status
update_job_step_status(p_sector,
p_job_name,
rec.step_name,
'Successful',
NULL,
NULL,
SYSDATE
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
-- Set Job Failed Status
update_job_status(p_sector,
p_job_name,
'Failed',
'Could Not Complete DB Job: ' || SQLERRM,
NULL,
SYSDATE
-- Set Job Step Failed Status
END;
rec.step_function is a procedure without any "When Others" clause. When that exception occurs I am expecting the "When Others" clause of the calling procedure is not capturing it some times. Is there any limitation to this? Any info in this regards would be really useful.
Thanks in advance.
Best Regards
Srikanth Tirandas

Could not reproduce.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure my_proc
2 as
3 v_num number;
4 begin
5 v_num := 1 / 0;
6* end;
SQL> /
Procedure created.
SQL> ed
Wrote file afiedt.buf
1 begin
2 begin
3 execute immediate 'begin my_proc; end;' ;
4 end;
5 exception
6 when others then
7 dbms_output.put_line(sqlerrm);
8* end;
SQL> /
ORA-01476: divisor is equal to zero
PL/SQL procedure successfully completed.
Can you provide code for your function when it does not work ? It seems some "rec.step_function" are coded to handle exceptions and hence you don't get any in outer loop.

Similar Messages

  • How can I open a cursor for dynamic sql statement

    Hi,
    I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
    CREATE OR REPLACE FUNCTION DEMO
    (MN_I in VARCHAR)
    return AB_OWNER.ABC_Type.NonCurTyp is
    RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
    sql_stmt VARCHAR2(4000);
    BEGIN
    sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
    OPEN RESULT1 FOR sql_stmt;
    END IF;
    return RESULT1;
    END DEMO;
    What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.

    Gangadhar Reddy wrote:
    I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
    Because this is what will happen when it runs a lot.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
    http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
    And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
    Flushing Shared Pool regularly
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
    >
    Ok, this is an easy one to diagnose.
    You are not using bind variables. This is terrible. Flushing the shared pool is a bad
    solution -- you are literally killing the performance on your box by not using them.
    If I was to write a book on how to build “non scalable applications in Oracle”, this
    would be the first and last chapter. This is a major cause of performance issues and a
    major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
    important shared memory data structure) operates is predicated on developers using bind
    variables. If you want to make Oracle run slowly, even grind to a total halt – just
    refuse to use them.
    >
    But, please feel free to go ahead with this successful implementation.
    I just hope anyone else who reads this doesn't make the same mistake.

  • Help required in changing to str for dynamic sql

    Hi
    I am trying to make this to string for dynamic sql, this is a part of the sql which is giving problem with p_..as parameters from proc. Help me in this , iam also seeing dbms _output but stil unable to format it to required error free string.
    || ' AND ( po.abbreviationprojectopportid LIKE '
    || '%'
    || 'NVL'
    || '('
    || p_opp_code
    || ', ''NULL'')'
    || '%'
    || ' OR co.companyname LIKE '
    || '%'
    || 'NVL'
    || '('
    || p_client_name
    || ', '' NULL'')'
    || '%'
    || ' OR le.line_item_amount = NVL '
    || ' ('
    || p_booking_amt
    || ', -0.197) '
    || 'OR po.dealcurrency = NVL '
    || '('
    || p_currency
    || ',''NULL'')'
    || 'OR be.booking_entry_id LIKE '
    || '%'
    || 'NVL ('
    || p_entry_id
    || ',''NULL'')'
    || '%'
    || ' OR le.line_item_id LIKE '
    || '%'
    || 'NVL ('
    || p_line_item
    || ',''null'')'
    || '%'
    || ' OR be.ticket_num LIKE '
    || '%'
    || 'NVL ('
    || p_ticket_num
    || ',''NULL'')'
    || '%'
    || ' OR be.updatedby LIKE '
    || '%'
    || 'NVL ('
    || p_user_name
    || ',''NULL'')'
    || '%'
    || ' OR credittransaction.acct_code ='
    || 'NVL ('
    || p_gl_account
    || ','
    || '-0.197)'
    || 'OR debittransaction.acct_code ='
    || 'NVL ('
    || p_gl_account
    || ', '
    || '-0.197) '
    || 'OR credittransaction.profit_ctr_code ='
    || 'NVL ('
    || p_profit_center
    || ','
    || ' -0.197)'
    || 'OR debittransaction.profit_ctr_code ='
    || 'NVL ('
    || p_profit_center
    || ','
    || '-0.197)'
    || ' OR le.sap_posting = NVL ('
    || p_sap_posting
    || ',''$'')'
    || 'OR cmis.cmis_code = NVL ('
    || p_cmis_nominal
    || ','' -0.197)'
    || 'OR sa.sap_code = NVL ('
    || p_sap_booking_entity
    || ', -0.197)'
    || ' OR (be.booking_date BETWEEN '
    || v_booking_date_from
    || 'AND '
    || v_booking_date_to
    || ')'
    || ' )'
    || 'ORDER BY '
    || p_sort_by
    || ' '
    || p_order;

    some errors.. Try this...
    ' SELECT be.booking_date bookingdate, '
    || ' be.booking_entry_id entryid, le.line_item_id itemid,'
    || ' po.abbreviationprojectopportid opportunitycode,'
    || ' co.companyname clientname, '
    || ' le.line_item_amount bookingamount,'
    || ' be.ticket_num ticketnum, po.dealcurrency currency,'
    || ' cmis.cmis_code cmis_nominal,'
    || ' sa.sap_code sap_booking_entity,'
    || ' (SELECT full_name '
    || ' FROM iba_employee '
    || ' WHERE TO_CHAR (employeeid) = be.updatedby) updatedby,'
    || ' be.updateddate updateddate, '
    || ' (SELECT le.line_item_amount * rate '
    || ' FROM iba_currencyconversion '
    || ' WHERE tocurrencycd = '
    || 'USD'
    || ' AND currencycd = po.dealcurrency '
    || ' AND conversiondate = be.booking_date) amountusd,'
    || 'debittransaction.acct_code debitglaccount,'
    || ' credittransaction.acct_code creditglaccount,'
    || ' debittransaction.profit_ctr_code debitprofitcenter,'
    || ' credittransaction.profit_ctr_code creditprofitcenter,'
    || ' debittransaction.amt debitamount,'
    || ' credittransaction.amt creditamount'
    || ' FROM rb_booking_entry be, '
    || ' rb_line_item le, '
    || ' rb_booking_period bp,'
    || ' rb_cmis_gl_account cmisgl,'
    || ' rb_cmis_account cmis,'
    || ' iba_projectopportunity po,'
    || ' iba_company co,'
    || ' rb_sap_account sa,'
    || ' (SELECT acctr.line_item_id line_item,'
    || ' sapgl_acc.account_code acct_code,'
    || ' acctr.amount amt,'
    || ' sappr.profit_center_code profit_ctr_code'
    || ' FROM rb_account_transaction acctr,'
    || ' rb_sap_profit_center sappr,'
    || ' rb_sap_gl_account sapgl_acc'
    || ' WHERE acctr.profit_center_id = sappr.profit_center_id '
    || ' AND acctr.gl_account_id = sapgl_acc.gl_account_id '
    || ' AND acctr.transaction_type = ''D'') debittransaction,'
    || ' (SELECT acctr.line_item_id line_item,'
    || ' sapgl_acc.account_code acct_code,'
    || ' acctr.amount amt,'
    || ' sappr.profit_center_code profit_ctr_code '
    || ' FROM rb_account_transaction acctr, '
    || ' rb_sap_profit_center sappr, '
    || ' rb_sap_gl_account sapgl_acc '
    || ' WHERE acctr.profit_center_id =sappr.profit_center_id '
    || ' AND acctr.gl_account_id = sapgl_acc.gl_account_id '
    || ' AND acctr.transaction_type = ''C'') credittransaction '
    || ' WHERE po.projectopportunityid = be.projectopportunityid '
    || ' AND be.booking_entry_id = le.booking_entry_id '
    || ' AND po.companyid = co.companyid '
    || ' AND bp.booking_period_id = be.booking_period_id '
    || ' AND cmis.cmis_id = cmisgl.cmis_id '
    || ' AND le.sap_id = sa.sap_id '
    || ' AND le.cmis_id = cmis.cmis_id '
    || ' AND debittransaction.line_item(+) = le.line_item_id '
    || ' AND credittransaction.line_item(+) = le.line_item_id '
    || ' AND ( po.abbreviationprojectopportid LIKE ' || '''%' || NVL(p_opp_code,'NULL') || '%'''
    || ' OR le.line_item_id LIKE '
    || '''%'
    || NVL (
    || p_line_item
    || ,'null')
    || '%'''
    | ' OR le.line_item_amount = '
    ||NVL(|| p_booking_amt, -0.197)
    || ' OR po.dealcurrency ='
    || NVL(p_currency,'NULL')
    || ' OR be.booking_entry_id LIKE '
    || '''%'
    || NVL (p_entry_id,'NULL')
    || '%'''
    || ' OR be.ticket_num LIKE '
    || '''%'
    || NVL (p_ticket_num,'NULL')
    || '%'''
    || ' OR be.updatedby LIKE '
    || '''%'
    || NVL (p_user_name,'NULL')
    || '%'''
    || ' OR credittransaction.acct_code ='
    || NVL (p_gl_account,-0.197)
    || ' OR debittransaction.acct_code ='
    || NVL (p_gl_account,  -0.197)
    || ' OR credittransaction.profit_ctr_code ='
    || NVL (p_profit_center, -0.197)
    || ' OR debittransaction.profit_ctr_code ='
    || NVL (p_profit_center, -0.197)
    || '  OR le.sap_posting = '
    ||NVL (p_sap_posting,'$')
    || ' OR cmis.cmis_code = '
    ||NVL (p_cmis_nominal, -0.197)
    || ' OR sa.sap_code = '
    || NVL (p_sap_booking_entity, -0.197)
    || '  OR (be.booking_date BETWEEN to_date('''
    || v_booking_date_from
    || ''') AND  to_date('''
    || v_booking_date_to
    || ''')'
    || ' OR co.companyname LIKE '
    || '''%'
    || NVL(p_client_name,'NULL')
    || '%'''
    || ' )'
    || 'ORDER BY  ' || p_sort_by || ',' || p_order;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Dynamic fetch for dynamic sql query

    Hi All,
    I want to dynamically create a query and fetch it into a dynamic cursor record...The structure of the record should be the same as that of the query...
    Can you suggest any method to do that.
    eg
    OPEN <dynamic cur> FOR <dynamic stmt>;
    LOOP
    FETCH <dynamic cur> INTO <dynamic rec>;
    END LOOP;
    CLOSE <dynamic cur>;
    How do I declare the dynamic rec here?I would not know the columns in the query beforehand either.
    Thanks,
    Merz
    Edited by: merz on Sep 12, 2011 5:02 PM
    Edited by: merz on Sep 12, 2011 5:03 PM

    merz wrote:
    Hi All,
    I want to dynamically create a query and fetch it into a dynamic cursor record...The structure of the record should be the same as that of the query...
    Can you suggest any method to do that.And how are you expecting to write an application around a dynamic query and dynamic structure that you don't know?
    Saying that, as others have said, there is the DBMS_SQL package which can be used for certain valid reasons such as the following example....
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Concatenate problem for Dynamic SQL statements

    Hi Experts ,
    I am building Dynamic SQL statements depending on the values which the user enters into the select option parameters .This dynamic query is passed to cl_sql_connection object for querying from another databasse
    So i wrote dynamic values for one select option spointof for the database field ppointofdelivery.
    loop at spointof.
    CONCATENATE ' pointofdelivery between ''' spointof-low''''
    ' AND ''' spointof-high''''
    INTO where_clause .
    endloop.
    The whereclause has value pointofdelivery between '123' and '124'.(if the user has entered 123 and 124 as values)
    This works fine . But my problem is I have to pass the fieldnames and operator dynamically into where_clause depending on User input.
    when i am writing code like the below
    field_name = ' pointofdelivery '.
    operator = '='.
    CONCATENATE field_name operator '''spointof-low''' INTO where_clause .
    the where_clause contains value
    pointofdelivery = ' spointof-low '
    and not pointofdelivery = ' 123 ' as expected .
    Do you know why this is haapening as it is not taking the value.
    Thanks
    Arshad

    Hi,
    there are lot of function modules..available...to build a where clause based on the select-options..
    check the FM FREE_SELECTIONS_RANGE_2_WHERE
    Thanks
    Naren

  • Allow Custom Text Entry for Drop down not working For Dynamic form

    Dear All,
    In drop down field Allow custom text entry is working fine if the form is save as a static pdf form file.But if the form is save as a Dynamic pdf form file it is not working.I can enter custom text in drop down field but after filling it up when I click on next field the text from the drop down is disappearing.
    If any body can please help me to solve this problem.
    Thanks a lot in advance
    Regards
    Rakesh

    Dear Jimmypham,
    Thanks a lot for your quick response.But it's not working for me.I have even tried with a form having only single field and save it as a dynamic pdf file.In that form also it's not working.The text which I have entered is disappearing when I click outside of this field.
    Can you please help me to find out the solution for this problem.
    Regards
    Rakesh

  • How to get a 'when others' exception raised.

    the 'when others' exception is raised usualy after a error occurs, but when does this actually occur? could some1 give an example??
    usually some error occurs and then a inbuilt exception is raised. but 'others' exception never seems to take place?

    The OTHERS handler takes control when the exception is not handled by any previous handlers.
    Here, we'll try to divide by zero. The no_data_found handler does not handle this error so control passes to the OTHERS section:
    sql>declare
      2    n  number;
      3  begin
      4    n := 1/0;
      5  exception
      6    when no_data_found then
      7      dbms_output.put_line( 'no data found exception' );     
      8    when others then
      9      dbms_output.put_line( 'when others exception' );
    10  end;
    11  /
    when others exception
    PL/SQL procedure successfully completed.Now, we'll try an operation which will raise the no_data_found exception. Here the ndf handler does handle the error and control never passes to the OTHERS section:
    sql>declare
      2    n  number;
      3  begin
      4    select 0
      5      into n
      6      from dual
      7     where dummy is null;
      8  exception
      9    when no_data_found then
    10      dbms_output.put_line( 'no data found exception' );
    11    when others then
    12      dbms_output.put_line( 'when others exception' );
    13  end;
    14  /
    no data found exception
    PL/SQL procedure successfully completed.

  • Open cursor for dynamic sql

    Hi
    I am using oracle 8.1.7 on solaris.
    I have created
    SQL> CREATE OR REPLACE PACKAGE TEST_PKG AS
    2 TYPE row_cursor IS REF CURSOR RETURN TEMP_TAB%ROWTYPE;
    3 PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor);
    4 END TEST_PKG;
    5 /
    Package created.
    now i am trying to create the procedure Return_Columns_proc by
    CREATE OR REPLACE PACKAGE BODY TEST_PKG AS
    PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor) AS
    QUERY_STR VARCHAR2(850);
    x number ;
    BEGIN
    x:=1;
    QUERY_STR :='SELECT * FROM temp_tab where order_line_id = '||x;
    OPEN c_return FOR QUERY_STR;
    END Return_Columns_proc;
    END TEST_PKG;
    I am getting following error.
    SQL> show error
    Errors for PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    8/4 PL/SQL: Statement ignored
    8/9 PLS-00455: cursor 'C_RETURN' cannot be used in dynamic SQL OPEN
    statement
    any help for this error.

    The error says it all. You have defined a strong ref cursor and it cannot be used with dynamic sql. However, that does not mean you cannot use the query directly in the OPEN clause
    OPEN c_Return FOR SELECT * FROM temp_tab where order_line_id = X ;

  • Open SYS_REFCURSOR for DYNAMIC SQL

    Hi!
    I have stored procedure like below:
    CREATE OR REPLACE
    PROCEDURE MYPROCEDURE
    cv_r OUT SYS_REFCURSOR
    AS
    lv_ExecuteString varchar(2000);
    BEGIN
      lv_ExecuteString := 'select 1 from dual';
      open cv_r for lv_ExecuteString;
      END MYPROCEDURE;and then
    SQL> var y refcursor
    SQL> execute myprocedure(:y);
    BEGIN myprocedure(:y); END;
    ERROR at line 1:
    ORA-00911: invalid character
    ORA-06512: at "BPATEL.MYPROCEDURE", line 9
    ORA-06512: at line 1shouldnt it suppose to work??? If not then How can I fill up OUT SYS_REFCURSOR with dynamic sql string ???
    although If I modify this below in my stored procedure it works fine:
    -- open cv_r for lv_ExecuteString;
    open cv_r for select 1 from dual;
    SQL> var y refcursor
    SQL> execute myprocedure(:y);
    PL/SQL procedure successfully completed.
    SQL> print y
             1
             1any idea?? why is it doing so???

    What version are you on? Works fine for me....
    ME_XE?CREATE OR REPLACE
      2  PROCEDURE MYPROCEDURE
      3  (
      4  cv_r OUT SYS_REFCURSOR
      5  )
      6  AS
      7  lv_ExecuteString varchar(2000);
      8  BEGIN
      9    lv_ExecuteString := 'select 1 from dual';
    10    open cv_r for lv_ExecuteString;
    11    END MYPROCEDURE;
    12  /
    Procedure created.
    Elapsed: 00:00:00.71
    ME_XE?var y refcursor
    ME_XE?execute myprocedure(:y);
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.03
    ME_XE?print :y
                     1
                     1
    1 row selected.
    Elapsed: 00:00:00.00
    ME_XE?@version
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    5 rows selected.
    Elapsed: 00:00:00.10

  • WHEN OTHERS not catching error

    I have the following SQL script:
    WHENEVER SQLERROR EXIT FAILURE
    SET VERIFY OFF
    DECLARE
    error_notes VARCHAR2(500);
    BEGIN
    process_test('TX', '&1');
    EXCEPTION
    WHEN OTHERS THEN
    log_error (
    SQLCODE,
    SUBSTR(SQLERRM, 1,150),
    SUBSTR(SQLERRM,151,150),
    error_notes);
    COMMIT;
    END;
    EXIT;
    This script is executed from a Unix command line SQLPLUS uid/pwd@SID @scriptname.sql. The catch is that I am trying to test my exception handling. To test the error I have intentionally renamed a table that the PL/SQL procedure 'process_test' is based on, so that it shows up as invalid. The failure is detected by the WHENEVER and the Unix status gets set to 1 so that the Unix end of the error trap operates fine. The problem is that there is nothing inserted into the error_log table. Is it that the WHENEVER clause at the top (there to propogate the error out to Unix) is causing the control to drop out of the block immediately after the error occurs so that my exception handler is not allowed to run? I need it in there to send the fail code out to Unix. The process in question is loading some tables with data from external tables, and after it loads a file it deletes it. I want to stop the deletion from occurring if the load didn't happen. The part is actually working, but it's not logging the error in the error table. Here's the error message, it if helps:
    process_test('TX', '/home/datatest/trans005.dat');
    ERROR at line 7:
    ORA-06550: line 7, column 5:
    PLS-00905: object OUTB.PROCESS_TEST is invalid
    ORA-06550: line 7, column 5:
    PL/SQL: Statement ignored
    Shouldn't this get caught by the WHEN OTHERS and dealt with before it exits the block, or is the WHENEVER SQLERROR clause causing control to move out of the block before the exception handler runs?

    Oh. Well, this SQL script executed a procedure that was invalid. Yes, it did show as invalid in PL/SQL Dev as soon as I changed the table name. I'm actually a big fan of packages and such. I was trying to think of a way to force an error in what is basically a simple system. There's not a lot of places for it to be broken. I can see now that I need to find a better place to break it. This way isn't allowing the PL/SQL exception handlers to be tested.
    The script itself is to be executed by a CRON job in Unix to fire off the file extracts. It's driven from Unix because we need to loop through a bunch of Unix file names. It creates a symbolic link so we can use External Tables to do the data extracts from the flat files, then it deletes the source file and moves on to the next one. The error trap is to stop the deletion of the source file if anything went wrong, so the file is still there for the next pass to load it. (Theoretically, once any errors have been corrected...)

  • Fail to Abend when Row Not Found for Update?

    I'm using Coldfusion 9 against a IBM mainframe DB2 database.  I have a condition that when a row is not found for update in a cfquery, execute an insert cfquery.  Sounds logical and easy, right?  Not so!  Error trapping is failing to return an error condition when the row was not found for update! 
    Here's the code:
    <cftry>
         <cfinclude template="qry_update_table.cfm">
         <cfcatch type="any">
              <cfinclude template="dsp_errorInformation.cfm">
              <cfabort>
         </cfcatch>
    </cftry>
    <cfdump var=#tmec04_result#><cfabort>
    The Query code is:
    <cflock timeout="15" name="UpdateTUID04Lock" type="exclusive">
         <cfquery datasource="#APPLICATION.DB2_DSN#" name="update_tuid04" result="tmec04_result">
              UPDATE #APPLICATION.SQLID#.TUID04
                   SET   MON_BEG_TIME  = <cfqueryparam value = #NEW_MON_BEG# cfsqltype="cf_sql_time">
                          , MON_END_TIME  = <cfqueryparam value = #NEW_MON_END# cfsqltype="cf_sql_time">
              WHERE  USER_ID    = <cfqueryparam value = #NEW_USER_ID# cfsqltype="cf_sql_varchar">
         </cfquery>
    </cflock>
    There is no row for the NEW_USER_ID, so I would expect an error condition.  No such luck.  The dump of temc04_result just shows me the SQL, the record count (0), the execution time (0), and the cached status (false).  No SQL code.  And a dump of CFCATCH shows that all is well.  I expected to get cfcatch.nativeerrorcode = 100 (Row not found).  Nope.  Got a zero.
    Any suggestions.

    Regarding this:
    There is no row for the NEW_USER_ID, so I would expect an error condition.
    Your expectation is incorrect.  What actually happens is that the query executes and no rows get updated.
    What has to happen is that you have to see whether or not the record is there, and if not, insert it.  There are lot's of ways to do that.  I think the simplest is an insert query,
    insert into yourtable
    (field1, field2, etc)
    select distinct value1, value2, etc
    from some small table
    where not exists (something)
    Followed by the update query.

  • This edition do not qualify for upgrade - SQL Express 2005

    Hello, 
    I hope somebody would be able to help me. 
    I am trying to upgrade an old Microsoft SQL Server 2005 - 9.00.3042.00 (Intel X86)   Feb  9 2007 22:47:07   Copyright (c) 1988-2005 Microsoft Corporation  Express Edition. 
    This one is SP2 as listed on http://sqlserverbuilds.blogspot.co.uk/ and I am trying to upgrade it to SP4. 
    However I get the error This edition do not qualify for upgrade, could anybody help?
    Many thanks, 
    Mohan

    Hello Mohan,
    Which installer have you used, may be this one here
    Microsoft SQL Server 2005 Service Pack 4 RTM ? As you can see in the "Details" it applys only for the Commercial Editions, you can not use it for the free Express.
    For Express Edition you have to use this one:
    Microsoft SQL Server 2005 Express Edition Service Pack 4
    Olaf Helper
    [ Blog] [ Xing] [ MVP]
    Hi Olaf, 
    Thank you for the response. 
    The one you asked me to use is a full SQL Server 2005 Express Edition Service Pack 4. However I need something to be able to just upgrade from Service Pack 2 to Service Pack 4, could you help?
    Many thanks, 
    Mohan

  • Start automatically CPS job waiting event when event not raised

    Hi,
    how to automatically start at a defined time a CPS job waiting an event, , if the event is not raised ?
    Clement

    Hi,
    You can have another event associated with such job chains(say Event_Force_Start) and define an OR condition in the event expression of the job chain. You can trigger the Event_Force_Start by anothe dummy script that excutes based on scheduled time or a submit frame. Thus yu can start the job at required time irrespective of the event under consideration being raised or not
    Regards
    Raj

  • Granting privilege through role not working for PL/SQL

    Version: 11.2.0.2
    In our shop, we don't grant privileges directly to a user, we grant it to a role and grant that role to the intended grantee.
    Granting privileges through a role seems to be fine with SQL Engine. But it doesn't work from PL/SQL engine.
    In the below example GLS_DEV user is granted SELECT access on SCOTT.pets table through a role called tstrole. GLS_DEV can select this table from SQL. But PL/SQL Engine doesn't seem to know this.
    Reproducing the issue:
    SQL> show user
    USER is "SCOTT"
    SQL> select * from pets;
    NAME
    PLUTO
    SQL> conn / as sysdba
    Connected.
    SQL> create user GLS_DEV identified by test1234 default tablespace TSTDATA;
    User created.
    SQL> alter user GLS_DEV quota 25m on TSTDATA;
    User altered.
    SQL> grant create session, resource to GLS_DEV;
    Grant succeeded.
    --- Granting SELECT privilege on scott.pets to tstrole and then grant this role to GLS_DEV.
    SQL> conn / as sysdba
    Connected.
    SQL>
    SQL> create role tstrole;
    Role created.
    SQL> grant select on scott.pets to tstrole;
    Grant succeeded.
    SQL> grant tstrole to GLS_DEV;
    Grant succeeded.
    SQL> conn GLS_DEV/test1234
    Connected.
    SQL>
    SQL> select * From scott.pets;
    NAME
    PLUTO
    ---- All fine till here. From SQL engine , GLS_DEV user can SELECT scott.pets table.
    --- Now , I am going to create a PL/SQL object in GLS_DEV which tries to refer scott.pets
    SQL> show user
    USER is "GLS_DEV"
    create or replace procedure my_proc
    is
    myvariable varchar2(35);
    begin
         select name into myvariable from scott.pets ;
         dbms_output.put_line(myvariable);
    end my_proc;
    Warning: Procedure created with compilation errors.
    SQL> show errors
    Errors for PROCEDURE MY_PROC:
    LINE/COL ERROR
    6/2      PL/SQL: SQL Statement ignored
    6/41     PL/SQL: ORA-01031: insufficient privileges
    SQL>
    SQL> 6
      6*    select name into myvariable from scott.pets ;
    --- PL/SQL Engine doesn't seem to know that GLS_DEV has select privilege on scott.pets indirectly granted through a role
    --- Fix
    --- Instead of granting privilege through a role, I am granting the SELECT privilege on scott.pets to GLS_DEV directly.
    --- The error goes away, I can compile and execute the procedure !!
    SQL> conn / as sysdba
    Connected.
    SQL>
    SQL> grant select on scott.pets to GLS_DEV;
    Grant succeeded.
    SQL> conn GLS_DEV/test1234
    Connected.
    SQL>
    SQL> create or replace procedure my_proc
    is
    myvariable varchar2(35);
    begin
            select name into myvariable from scott.pets ;
            dbms_output.put_line(myvariable);
    end my_proc;  2    3    4    5    6    7    8    9   10
    11  /
    Procedure created.
    SQL> set serveroutput on
    SQL> exec my_proc;
    PLUTO
    PL/SQL procedure successfully completed.Has anyone encountered the same issue ?

    You really should start your own new thread for this question instead of resurrecting an old one, but to answer your question.
    There are two things going on here. First, there are a number of aler session commands that can be used by any user regardless of what privileges they are granted. Although I do not have the entire list at hand, things like nls_date_format and current_schema are available to all users, sort of like the grants to public in the data dictionary.
    Second, when you use execute immediate, the PL/SQL engine never really sees the statement, as far as the compiler is concerned it is just a string. It is only when the string is passed to the sql engine that permissions are checked, and there roles are not enabled.
    SQL> create role t_role;
    Role created.
    SQL> grant select on ops$oracle.t to t_role;
    Grant succeeded.
    SQL> create user a identified by a default tablespace users;
    User created.
    SQL> grant create session, create procedure to a;
    Grant succeeded.
    SQL> grant t_role to a;
    Grant succeeded.
    SQL> connect a/a
    Connected.
    SQL> select * from ops$oracle.t;
            ID DESCR
             1 One
             1 Un
    SQL> create function f (p_descr in varchar2) return number as
      2     l_num number;
      3  begin
      4     select id into l_num
      5     from ops$oracle.t
      6     where descr = p_descr;
      7     return l_num;
      8  end;
      9  /
    Warning: Function created with compilation errors.
    SQL> show error
    Errors for FUNCTION F:
    LINE/COL ERROR
    4/4      PL/SQL: SQL Statement ignored
    5/20     PL/SQL: ORA-00942: table or view does not exist
    SQL> create or replace function f (p_descr in varchar2) return number as
      2     l_num number;
      3  begin
      4     execute immediate 'select id from ops$oracle.t where descr = :b1'
      5                       into l_num using p_descr;
      6     return l_num;
      7  end;
      8  /
    Function created.
    SQL> select f('One') from dual;
    select f('One') from dual
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at "A.F", line 4John

  • 'is null' not working in dynamic sql and SQl Query component (OBPM 10gr3)

    I'm using a SQL Query component with sql like this
    'select col1, col2 from table where col3 is null'
    for some reason this does not work.
    Has anybody faced this issue? Is there a known bug with handling nulls
    Thanks

    plz post which DB version u r working with
    dont use paramters in Procedure with : sign
    Write simply the name of the Paramters like p_userid etc etc
    this might help u as well
    http://baigsorcl.blogspot.com/2010/02/get-rid-of-addtional-quotes-with-quote.html

Maybe you are looking for

  • In OBIEE rpd convert varchar to datetime

    Hello, Can anyone help one how can we convert a column that is set to varchar to datetime in obiee; Suppose COLUMN_A is varchar and keeps value like '2008-12-30 10:11:22' and we want to convert it DATETIME. Thanks and Regards

  • Nokia Lumia 520 data cable removing

    I bought Lumia 520 last week. Haven't installed windows 8 software with my windows 7 laptop yet. but i did connect  using the data cable to transfer some music. After i was done transferring data i found no safely remove hardware option.  So i had to

  • HTTP_RESP_STATUS_CODE_NOT_OK.  Pls help

    Hello, When I am executing my scenario I am getting below error in sxmb_moni. <SAP:Category>XIServer</SAP:Category>   <SAP:Code area="INTERNAL">HTTP_RESP_STATUS_CODE_NOT_OK</SAP:Code>   <SAP:P1>401</SAP:P1>   <SAP:P2>Unauthorized</SAP:P2> Pls advice

  • MDB / threads allocation : doubt

              Hello Tom,           you wrote that :           "Remember that an MDB will use up to half+1 of the thread pool."           Sorry, but I've not understood.           Do you mean that, if I have one MDB, 12 available threads (considering 3 th

  • GS70 White screen issue

    So, about a month ago. I RMA'ed my GS70. I just booted it up the other day and my screen was white. Now I got it back about a week ago. From an official MSI Center. It worked great for about a week. Now I just booted it up again. And it has the same