Max open Cursor / no data found

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.
cutie_smilyAsked:
Who is Participating?
 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
>>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
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
>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
 
cutie_smilyAuthor Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
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
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
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
 
cutie_smilyAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.