for acct in (select ucracct_cust_code,
ucracct_prem_code,
ucracct_cycl_code,
ucracct_status_ind
from ucracct -------数据50万
where ucracct_cycl_code>=vcycle_code_begin
and ucracct_cycl_code<=vcycle_code_end
and (vacct_type='%' or ucracct_status_ind=vacct_type)
)
loop
if mod(vrows,vinterval)=0 then
for shis in ( select urrshis_serv_num,
urrshis_styp_code,
urrshis_scat_code,
urrshis_action_date,
urrshis_actn_code,
urrshis_rtyp_code,
urrshis_reading,
urrshis_multiplier,
urrshis_consumption,
urrshis_dos,
urrshis_charge_date,
urrshis_chrg_calc_num
from urrshis ---数据上千万
where urrshis_prem_code=acct.ucracct_prem_code
and urrshis_cust_code=acct.ucracct_cust_code
and urrshis_action_date < sysdate - 45
and nvl(urrshis_actn_code,'*')<>'SKIP'
and nvl(urrshis_charge_date,to_date('12/31/2099','mm-dd-yyyy')) = to_date('12/31/2099','mm-dd-yyyy')
)
loop
...这样的嵌套循环,如何优化呢??不能写成sql,不能动数据库结构。望达人相助。
ucracct_prem_code,
ucracct_cycl_code,
ucracct_status_ind
from ucracct -------数据50万
where ucracct_cycl_code>=vcycle_code_begin
and ucracct_cycl_code<=vcycle_code_end
and (vacct_type='%' or ucracct_status_ind=vacct_type)
)
loop
if mod(vrows,vinterval)=0 then
for shis in ( select urrshis_serv_num,
urrshis_styp_code,
urrshis_scat_code,
urrshis_action_date,
urrshis_actn_code,
urrshis_rtyp_code,
urrshis_reading,
urrshis_multiplier,
urrshis_consumption,
urrshis_dos,
urrshis_charge_date,
urrshis_chrg_calc_num
from urrshis ---数据上千万
where urrshis_prem_code=acct.ucracct_prem_code
and urrshis_cust_code=acct.ucracct_cust_code
and urrshis_action_date < sysdate - 45
and nvl(urrshis_actn_code,'*')<>'SKIP'
and nvl(urrshis_charge_date,to_date('12/31/2099','mm-dd-yyyy')) = to_date('12/31/2099','mm-dd-yyyy')
)
loop
...这样的嵌套循环,如何优化呢??不能写成sql,不能动数据库结构。望达人相助。
--类型转换想必要这样吧
to_date('12/31/2099','mm/dd/yyyy')
看可以采用数组 以及 使用bulk collect into 代替第一层循环
urrshis_styp_code,
urrshis_scat_code,
urrshis_action_date,
urrshis_actn_code,
urrshis_rtyp_code,
urrshis_reading,
urrshis_multiplier,
urrshis_consumption,
urrshis_dos,
urrshis_charge_date,
urrshis_chrg_calc_num
from urrshis ---数据上千万
where urrshis_prem_code=acct.ucracct_prem_code
and urrshis_cust_code=acct.ucracct_cust_code
Oracle 提供了 fetch bulk collect 来批量取游标中的数据。能在读取游标中大量数据的时候提升效率。
如果好改的话,还是用这个效果应该会更明显。
你说的这个,你可以实际试试,看会不会有明显效果。呵呵。