Hi,
I am trying to create two explicit cursors to read data from a table and a view respectively..
The first cursor will get customers addresses in a table and the second cursor will get the bill charges from a view and pass it to another stored procedure which will then output it as an Electronic Bill Notification to the customers email address.
Below is the nested cursor I created and I am not too sure what its strengths will be like. The reason why I am using this is because I am dealing with data records over 10,000. i got an error which is
[
Error] Syntax check (29: 16): ERROR line 29, col 16, ending_line 29, ending_col 20, Found 'table', Expecting: ; -or- .. := DEFAULT NOT NULL -or- % -or- ( . @
when compiling the script.
CREATE OR REPLACE PROCEDURE TMIS.EBILLS2(C_NUM NUMBER) IS
/
--DECLARE
CURSOR EDETAILS
IS
SELECT DISTINCT(CUSTOMER_ACCOUNT_NUMBER) as "CUST_NUM",CUSTOMER_NAME ,EMAIL,
CURSOR (select R_CHARGES_TOTAL
from BILL_LEDGERS b
where b.custkeyvalue=c.customer_account_number)
FROM EBILL_CUSTOMERS c
AND CYCLE = C_NUM
ORDER BY 2;
-- Declare Variables to hold Values from Outer Cursor
icount number default 0;
imonth varchar2(10);
crlf VARCHAR2(2) := chr(13)||chr(10);
ierr varchar2(100);
imail VARCHAR2(80);
istring VARCHAR2(1000);
-- Declare PL/SQL Table to hold Values from Inner Cursor
i_charges is table of
BILL_LEDGERS@ABS_SYSTEM.TELIKOMPNG.COM.PG.R_CHARGES_TOTAL%type index by binary_integer ;
BEGIN
icount := 0;
imonth := to_char(sysdate,'MON-YYYY');
dbms_output.enable(200000);
FOR l in edetails
LOOP
BEGIN
--fetch values for outter cursor and display
imail := erow.email;
istring := l.cust_num ||' ; '|| l.customer_name ||' ; '||imonth ||' ; '|| imail;
icount := icount + 1;
dbms_output.put_line(ICOUNT||' | '|| imonth ||' | '|| l.cust_num ||' | '|| l.customer_name ||' | '|| imail);
-- Fetch Values from Inner Cursor
for ed in ref_cur
loop
begin
icharges:=ed.R_CHARGES_TOTAL;
-- Print Details to ebill notification
if l_cust_num=erow.cust_num
then Dbms_Output.Put_Line ( icharges );
end if;
end loop;
END LOOP;
EXCEPTION WHEN OTHERS THEN
--ierr := substr(sqlerrm,1,1000);
dbms_output.put_line(sqlerrm);
-- raise_application_error(-20000, 'Unable to send ebill notification: '|| sqlerrm);
END;
EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
dbms_output.put_line(sqlerrm);
--raise_application_error(-50000, 'Unable to send ebill notification: '|| sqlerrm);
END;
/
Please is there a better way I can do this?
Many thanks
Delisha