zoukankan      html  css  js  c++  java
  • for all的使用,批量绑定

    • 在insert语句中使用批量绑定
      • 未使用for all的情况
    declare
        type id_table_type is table of number(6) index by binary_integer;
        type name_table_type is table of varchar2(10) index by binary_integer;
        id_table id_table_type;
        name_table name_table_type;
        start_time number(10);
        end_time number(10);
    begin
        for i in 1..50000
        loop
            id_table(i) := i;
            name_table(i) := 'Name' || to_char(i);
        end loop;
        start_time := dbms_utility.get_time;
        for i in 1..id_table.count
        loop
            insert into demo values(id_table(i), name_table(i));
        end loop;
        end_time:= dbms_utility.get_time;
        dbms_output.put_line('总计时间(秒)'||to_char((end_time-start_time)/100));
    end;
    
    使用for all的情况
    declare
        type id_table_type is table of number(6) index by binary_integer;
        type name_table_type is table of varchar2(10) index by binary_integer;
        id_table id_table_type;
        name_table name_table_type;
        start_time number(10);
        end_time number(10);
    begin
        for i in 1..50000
        loop
            id_table(i) := i;
            name_table(i) := 'Name' || to_char(i);
        end loop;
        start_time := dbms_utility.get_time;
        forall i in 1..id_table.count
    
            insert into demo values(id_table(i), name_table(i));
    
        end_time:= dbms_utility.get_time;
        dbms_output.put_line('总计时间(秒)'||to_char((end_time-start_time)/100));
    end;
    
    • 数据准备
    create table demo2(id number(3));
    insert into demo2 values(10);
    insert into demo2 values(11);
    insert into demo2 values(12);
    insert into demo2 values(13);
    insert into demo2 values(14);
    insert into demo2 values(15);
    
    create table demo2_bak as select * from demo2 where 1=2
    • DML之delete
    declare  
    type id_table_type is table of number(6);  
    id_table id_table_type;  
    begin  
    id_table:=id_table_type(11,null,12,null,13,null);  
    forall i in indices of id_table  
        delete from  demo2 where id=id_table(i);  
    end;
    • DML之insert
    declare  
    type id_table_type is table of number(6);  
    id_table id_table_type;  
    begin  
    id_table:=id_table_type(11,null,12,null,13,null);  
    forall i in indices of id_table  
        -- dbms_output.put_line('value is :'||id_table(i));
        insert into demo2_bak values(id_table(i));
    end;
    • DML之update
    declare  
    type id_table_type is table of number(6);  
    id_table id_table_type;  
    begin  
    id_table:=id_table_type(11,null,12,null,13,null);  
    forall i in indices of id_table  
        -- dbms_output.put_line('value is :'||id_table(i));
        update demo2_bak set id=0 where id=id_table(i);
    end;

    注意:for all只能用于DML操作,不能用于查询等操作(比如将元素进行显示dbms_output.put_line();)

  • 相关阅读:
    如何让某一个窗口位于所有的窗口最上面
    CString ,BSTR ,LPCTSTR之间关系和区别
    PPT演讲放映技巧__备注的妙用
    链接集合
    男人靠什么吸引女人
    配置IISweb容器之程序下载
    用windows2003免费搭建外网流媒体服务器
    人类记忆规律及法则
    MFC基础知识总结
    VC 定位窗体常用方法
  • 原文地址:https://www.cnblogs.com/yldf/p/7743596.html
Copyright © 2011-2022 走看看