?
Solved

Max open Cursor / no data found

Posted on 2006-11-13
6
Medium Priority
?
8,654 Views
Last Modified: 2011-08-18
Hello All,

The below procedure is to check for duplicates. If there are no duplicates then call the insert procedure and load the records to target. At this point there are no records in the target so there should be no duplicates.

When I run my procedure I am getting two types of errors; in the first run I am getting the below error and in the second run maximum open cursors exceeded error in the other insert procedure.  

Error one:
----------
ORA-01403: no data found
ins_rec_to_table: Oracle Error:100:ORA-01403: no data found

Error two:
----------
dup_check_exception
check_for_dups: Oracle Error:-1000:ORA-01000: maximum open cursors exceeded

Thanks for all the inputs. I will increase the points according.


Below is my procedure .

********************************************************************************
FUNCTION check_for_dups(IN_CUST_CD varchar2,outrec_in IN DRUGDS_CUST%ROWTYPE , IN_DRU_RXCLAIM_NBR DRUGDS_CUST.DRU_RXCLAIM_NBR%TYPE, ErrorString OUT VARCHAR2)
RETURN BOOLEAN
IS

v_dup_found NUMBER := 0;
v_out_trgt_col_cd  VARCHAR2(100);

v_dup_stmt                     long;
dup_where_list                 VARCHAR2(32767);

feedback                       number(10);
r_feedback                     number(10);
j                              number(10) := 1;
c2                             integer;

Cursor dup_cur is
select *
from MD_CUST_DYN_SQL
where CUST_CD = IN_CUST_CD
and SRC_COL_DUP_IND='Y'
order by TRGT_COL_ORDER_NBR;


BEGIN

dbms_output.put_line('in_dup_check');

FOR rec in dup_cur
LOOP

  If rec.SRC_COL_DUP_IND = 'Y'  THEN  
     
     if rec.SRC_COL_DUP_FUNC_TXT IS NOT NULL THEN
       
        dup_where_list := dup_where_list||rec.SRC_COL_DUP_FUNC_TXT||'('||rec.TRGT_COL_NM;
        if rec.SRC_COL_DUP_FUNC_PARM_TXT IS NOT NULL THEN
          dup_where_list := dup_where_list||','||rec.SRC_COL_DUP_FUNC_PARM_TXT||') = '  ;
        else
           dup_where_list := dup_where_list||') = '  ;
        end if;
     else
        dup_where_list := dup_where_list||rec.TRGT_COL_NM||' = ';
     end if;
 ---    DBMS_OUTPUT.PUT_LINE('dup_where_list =' ||dup_where_list);
     
     if rec.TRGT_COL_DUP_FUNC_TXT IS NOT NULL THEN        
        dup_where_list := dup_where_list||rec.TRGT_COL_DUP_FUNC_TXT||'( :u'||j;
        if rec.TRGT_COL_DUP_FUNC_PARM_TXT IS NOT NULL THEN
           dup_where_list := dup_where_list||','||rec.TRGT_COL_DUP_FUNC_PARM_TXT||') '  ;
        else
           dup_where_list := dup_where_list||') '  ;
        end if;
     else
        dup_where_list := dup_where_list||' :u'||j;
     end if;
     dup_where_list := dup_where_list||' AND ';
     j := j + 1;
  End if;  
---DBMS_OUTPUT.PUT_LINE('dup_where_list1 =' ||dup_where_list);
END LOOP;

dup_where_list := ' WHERE '||RTRIM(dup_where_list,' AND ') ;
----DBMS_OUTPUT.PUT_LINE('dup_where_list3 =' || dup_where_list);

v_dup_stmt     := 'SELECT COUNT(*)
                        FROM DRUGDS_CUST'||dup_where_list ;


c2 := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c2,v_dup_stmt,DBMS_SQL.NATIVE);
DBMS_SQL.BIND_VARIABLE(c2, 'u1', outrec_in.PRES_RX_NUM);
DBMS_SQL.BIND_VARIABLE(c2, 'u2', outrec_in.PRES_FILL_DATE);
DBMS_SQL.BIND_VARIABLE(c2, 'u3', outrec_in.REFILL_INDICATOR);
DBMS_SQL.BIND_VARIABLE(c2, 'u4', outrec_in.DRUG_NDC#);
DBMS_SQL.BIND_VARIABLE(c2, 'u5', TRIM(outrec_in.PHARMACY_NABP#));
DBMS_SQL.BIND_VARIABLE(c2, 'u6', outrec_in.METRIC_UNITS);
DBMS_SQL.BIND_VARIABLE(c2, 'u7', TRIM(IN_DRU_RXCLAIM_NBR));
DBMS_SQL.DEFINE_COLUMN(c2,1,v_dup_found);

feedback:=DBMS_SQL.EXECUTE(c2);
r_feedback:=DBMS_SQL.FETCH_ROWS(c2);

IF r_feedback > 0 THEN
DBMS_SQL.COLUMN_VALUE(c2,1,v_dup_found);
End IF;

IF v_dup_found = 0
THEN
      RETURN FALSE;
ELSE
      RETURN TRUE;
END IF;
DBMS_SQL.CLOSE_CURSOR(c2);

EXCEPTION
        WHEN OTHERS THEN
        dbms_output.put_line('dup_check_exception');
        ErrorString := 'check_for_dups: Oracle Error:' || SQLCODE || ':'|| SQLERRM;
     RETURN FALSE;
END check_for_dups;


Thanks for all the inputs.
0
Comment
Question by:cutie_smily
6 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 600 total points
ID: 17932426
>ORA-01403: no data found
>ins_rec_to_table: Oracle Error:100:ORA-01403: no data found

means that the query did not return any rows (could be expected).
you might handle that explicitely:

...
EXCEPTION
    WHEN NO DATA FOUND THEN
        // ... handle it
        NULL;

    WHEN OTHERS THEN
...




>dup_check_exception
>check_for_dups: Oracle Error:-1000:ORA-01000: maximum open cursors exceeded

this is a server setting, usually a quite low setting (max_cursors). you might increase that, depending on the version you have to bounce the database to get the value applied

0
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1200 total points
ID: 17932502
>>check_for_dups: Oracle Error:-1000:ORA-01000: maximum open cursors exceeded

The answer is pretty much the same as it was in your last question ( Q_22052461.html ) about open cursors:  you are 'RETURN'ing from the function before you close the cursor.
---------
IF v_dup_found = 0
THEN
      RETURN FALSE;
ELSE
      RETURN TRUE;
END IF;
---
---  The Function will NEVER get here!!!!!!!!!!!!!!!
---
DBMS_SQL.CLOSE_CURSOR(c2);
0
 

Author Comment

by:cutie_smily
ID: 17932843
Thanks slightwv.

I moved the closing cursor above.

DBMS_SQL.CLOSE_CURSOR(c2);
IF v_dup_found = 0
THEN
      RETURN FALSE;
ELSE
      RETURN TRUE;
END IF;

But I am still getting the below error. Any idea will be appreciated.

ORA-01403: no data found
ins_rec_to_table: Oracle Error:100:ORA-01403: no data found

Thanks
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 78

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1200 total points
ID: 17933071
That's where angelIII's answer comes in.  If NO_DATA_FOUND is an OK exception, you need to explicitly add it to your exception handler.

Also,
That exception is probably coming from the other procedure and not the code you posted since the function you posted has:
 ErrorString := 'check_for_dups: Oracle Error:' || SQLCODE || ':'|| SQLERRM;

and the error message you give seems to come from: 'ins_rec_to_table'.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 17935090
no_data_found can be easily debugged with dbms_output.put_line(...);

Add some debug messages across your full code to see how control flows through the code. Though this is known to everyone, it will help you to fix the error easily for yourself.

Thanks
0
 

Author Comment

by:cutie_smily
ID: 17941610
Thanks for all the inputs and apologize for getting back late as it took many hrs to figure out the problem. The problem is one of the select queries where clause values where passed as zeros where it is returning no data found.

Thanks again for all the inputs. I will close this post now.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question