多分配給少的寫法

來源:互聯網
上載者:User

declare
 type yy_assign_type is table of yy_assign_tbd20091001%rowtype index by binary_integer;
  type customer_list_type is table of custmer_list_tbd20091001%rowtype index by binary_integer;
 V_SALES_ID      VARCHAR2(32);
  v_num pls_integer := 0;
  v_mod_num pls_integer:=0;
  old_num pls_integer:=0;
  yy_assign_table     yy_assign_type;
  customer_list_table     customer_list_type;
begin
 select yy.* bulk collect
    into yy_assign_table
    from yy_assign_tbd20091001 yy
   where yy.res_type ='idsType' and rownum<500
 order by yy.serial_num;
 
  select * bulk collect
    into customer_list_table
    from custmer_list_tbd20091001
   where customer_type ='X' ORDER BY sales_id;
for i in 1 .. yy_assign_table.count loop
    if(yy_assign_table(i).SERIAL_NUM = old_num) then
       update   yy_assign_tbd20091001 set is_used='y',CUSTOMER_ATTR=V_SALES_ID where  member_id =  yy_assign_table(i).MEMBER_ID;
                       
    else
        v_mod_num :=mod(i,customer_list_table.count);
        if(v_mod_num=0) then
                v_mod_num:= customer_list_table.count;     
        end if ;
        V_SALES_ID :=customer_list_table(v_mod_num).SALES_ID;
        update   yy_assign_tbd20091001 set is_used='y',CUSTOMER_ATTR=V_SALES_ID where  member_id =  yy_assign_table(i).MEMBER_ID;
         old_num :=yy_assign_table(i).SERIAL_NUM ;
    end if ;
    dbms_output.put_line(yy_assign_table(i).SERIAL_NUM);
end loop;
  COMMIT;
EXCEPTION
  WHEN OTHERS THEN
    Dbms_Output.put_line('error encounter');
    ROLLBACK;
END;
覺得這個辦法比以前的for 迴圈好了很多 就自己想了一下 寫寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.