DECLARE
CURSOR c_br IS SELECT * FROM broker_ret;
CURSOR c_hfhd (p_cuno VARCHAR2) IS
SELECT * FROM hs_his.hisfuholddrop
WHERE fund_account=p_cuno;
r_br broker_ret%ROWTYPE;
r_hfhd hs_his.hisfuholddrop%ROWTYPE;
BEGIN
OPEN c_br;
LOOP
FETCH c_br INTO r_br;
EXIT WHEN c_br%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( 'part1 ok! ');
OPEN c_hfhd(r_br.cust_no);
LOOP
FETCH c_hfhd INTO r_hfhd;
EXIT WHEN c_hfhd%NOTFOUND;
IF r_br.ret_mode= '1 '
THEN execute immediate 'insert into broker_fund values
(r_hfhd.initdate,r_br.broker_no,r_br.cust_no,r_br.exch_code,r_br.vari_code,r_br.ret_mode,r_br.amt,r_br.business_amount*amt) ';
END IF;
IF r_br.ret_mode= '2 '
THEN execute immediate 'insert into broker_fund(tx_date,broker_no,cust_no,exch_code,vari_code,ret_mode,amt,fare) values
(r_hfhd.initdate,r_br.broker_no,r_br.cust_no,r_br.exch_code,r_br.vari_code,r_br.ret_mode,r_br.amt,r_br.total_fare*amt) ';
END IF;