Link to home
Start Free TrialLog in
Avatar of cutie_smily
cutie_smily

asked on

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.
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cutie_smily
cutie_smily

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.