Solved

Max open Cursor / no data found

Posted on 2006-11-13
6
8,620 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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 150 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 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 300 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 300 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
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
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

776 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