ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle 10g values of 和indices of 初次接触

oracle 10g values of 和indices of 初次接触

原创 Linux操作系统 作者:sieper 时间:2010-12-22 16:14:55 0 删除 编辑

values of 和indices of是oracle 10g的新特性。在批量处理中提高性能,适用于处理嵌套集合,稀疏集合时,以避免丢失记录异常和创建多余副本。
在使用时,
forall  var    in values of collection 的 collection定义需要为var的类型。
forall var in indices of collection 的collection定义可以使其他对象,这里的var相当于collection的下标

create or replace procedure p_product_price_ex(p_company varchar2) is

  type t_product_id is table of product.product_id%type index by pls_integer;
  type t_yyyy is table of product.yyyy%type index by pls_integer;
  --type t_price is table of product.price%type index by pls_integer;

  TYPE t_partions IS TABLE OF PLS_INTEGER INDEX BY PLS_INTEGER;

  v_product_id t_product_id;
  v_yyyy       t_yyyy;
  --v_price t_price;

  v_down_list t_partions;
  v_up_list   t_partions;

  procedure p_retrive_datas is
    v_sql varchar2(256);
  begin
    select p.product_id, p.yyyy bulk collect
      into v_product_id, v_yyyy
      from product_1 p
     where p.company = p_company;
  end;

  procedure p_partition_datas is
  begin
    for i in v_product_id.first .. v_product_id.last loop
      if mod(v_product_id(i), 2) = 0 then
        v_down_list(i) := i;
      else
        v_up_list(i) := i;
      end if;
    end loop;
  end;

  procedure p_product_price_down is
  begin
    forall j in values of v_down_list
      insert into product_down (product_id) values (v_product_id(j));
      commit;
  end;
  procedure p_product_price_up is
  begin
    forall k in values of v_up_list
      insert into product_up (product_id) values (v_product_id(k));
      commit;
  end;

begin
  p_retrive_datas;
  p_partition_datas;
  p_product_price_down;
  p_product_price_up;
end;

 


create or replace procedure p_product_price_ex2(p_company varchar2) is

  type t_product_id is table of product.product_id%type index by pls_integer;
  type t_yyyy is table of product.yyyy%type index by pls_integer;

 

  v_product_id t_product_id;
  v_yyyy       t_yyyy;

  TYPE guide_aat IS TABLE OF BOOLEAN INDEX BY PLS_INTEGER;

  v_down_list guide_aat;
  v_up_list   guide_aat;

  procedure p_retrive_datas is
    v_sql varchar2(256);
  begin
    select p.product_id, p.yyyy bulk collect
      into v_product_id, v_yyyy
      from product_1 p
     where p.company = p_company;
  end;

  procedure p_partition_datas is
  begin
    for i in v_product_id.first .. v_product_id.last loop
      if mod(v_product_id(i), 2) = 0 then
        v_down_list(i) := TRUE;
      else
        v_up_list(i) := TRUE;
      end if;
    end loop;
  end;

  procedure p_product_price_down is
  begin
    forall j in INDICES of v_down_list
      insert into product_down (product_id) values (v_product_id(j));
      commit;
  end;
  procedure p_product_price_up is
  begin
    forall k in INDICES of v_up_list
      insert into product_up (product_id) values (v_product_id(k));
      commit;
  end;

begin
  p_retrive_datas;
  p_partition_datas;
  p_product_price_down;
  p_product_price_up;
end;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11813230/viewspace-682404/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-03-17

  • 博文量
    87
  • 访问量
    210543