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_NB R%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_d up_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_CO L_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.S RC_COL_DUP _FUNC_PARM _TXT||') = ' ;
else
dup_where_list := dup_where_list||') = ' ;
end if;
else
dup_where_list := dup_where_list||rec.TRGT_C OL_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_C OL_DUP_FUN C_TXT||'( :u'||j;
if rec.TRGT_COL_DUP_FUNC_PARM _TXT IS NOT NULL THEN
dup_where_list := dup_where_list||','||rec.T RGT_COL_DU P_FUNC_PAR M_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('d up_where_l ist1 =' ||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_li st ;
c2 := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c2,v_dup_st mt,DBMS_SQ L.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_NA BP#));
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_fo und);
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_fou nd);
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_exce ption');
ErrorString := 'check_for_dups: Oracle Error:' || SQLCODE || ':'|| SQLERRM;
RETURN FALSE;
END check_for_dups;
Thanks for all the inputs.
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_NB
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_d
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_CO
if rec.SRC_COL_DUP_FUNC_PARM_
dup_where_list := dup_where_list||','||rec.S
else
dup_where_list := dup_where_list||') = ' ;
end if;
else
dup_where_list := dup_where_list||rec.TRGT_C
end if;
--- DBMS_OUTPUT.PUT_LINE('dup_
if rec.TRGT_COL_DUP_FUNC_TXT IS NOT NULL THEN
dup_where_list := dup_where_list||rec.TRGT_C
if rec.TRGT_COL_DUP_FUNC_PARM
dup_where_list := dup_where_list||','||rec.T
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('d
END LOOP;
dup_where_list := ' WHERE '||RTRIM(dup_where_list,' AND ') ;
----DBMS_OUTPUT.PUT_LINE('
v_dup_stmt := 'SELECT COUNT(*)
FROM DRUGDS_CUST'||dup_where_li
c2 := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c2,v_dup_st
DBMS_SQL.BIND_VARIABLE(c2,
DBMS_SQL.BIND_VARIABLE(c2,
DBMS_SQL.BIND_VARIABLE(c2,
DBMS_SQL.BIND_VARIABLE(c2,
DBMS_SQL.BIND_VARIABLE(c2,
DBMS_SQL.BIND_VARIABLE(c2,
DBMS_SQL.BIND_VARIABLE(c2,
DBMS_SQL.DEFINE_COLUMN(c2,
feedback:=DBMS_SQL.EXECUTE
r_feedback:=DBMS_SQL.FETCH
IF r_feedback > 0 THEN
DBMS_SQL.COLUMN_VALUE(c2,1
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_
ErrorString := 'check_for_dups: Oracle Error:' || SQLCODE || ':'|| SQLERRM;
RETURN FALSE;
END check_for_dups;
Thanks for all the inputs.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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.
Thanks again for all the inputs. I will close this post now.
ASKER
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