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,不能动数据库结构。望达人相助。

解决方案 »

  1.   


    --类型转换想必要这样吧
    to_date('12/31/2099','mm/dd/yyyy')
      

  2.   

    来学习学习,前几天才刚刚接触Oracle
      

  3.   

    不能通过优化sql语句 达到目的吗?
      

  4.   

    很难,看你sql不复杂.需要注意的是尽量不要在有索引的字段上用函数,这样会导致无法利用索引.
      

  5.   


    看可以采用数组 以及 使用bulk collect into 代替第一层循环
      

  6.   

    对,看第二个游标的条件 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
      

  7.   

    wkc168说到的 fetch bulk collect into 貌似不错。
    Oracle 提供了 fetch bulk collect 来批量取游标中的数据。能在读取游标中大量数据的时候提升效率。
    如果好改的话,还是用这个效果应该会更明显。
    你说的这个,你可以实际试试,看会不会有明显效果。呵呵。