假如说我要插入100000条数据到dbo.SYS_LOG中,在SQL Server中是如下插入:
declare @i int
set @i=1
while @i<=20000
begin
insert into dbo.SYS_LOG(F_ID,F_NAME,F_DELETEFLAG) values(@i,'系统管理员',0)
set @i=@i+1
end请问在ORACLE中怎么样能实现这个功能,方法越多越好

解决方案 »

  1.   


    declare
    i number;
    begin
    i:=1;
    while i<=20000 loop
    insert into SYS_LOG(F_ID,F_NAME,F_DELETEFLAG) values(i,'系统管理员',0);
    i:=i+1;
    commit;
    end loop;
    end;
      

  2.   

    --或者这样
    begin
    for i in 1..20000 loop
    insert into SYS_LOG(F_ID,F_NAME,F_DELETEFLAG) values(i,'系统管理员',0);
    commit;
    end loop;
    end;
      

  3.   

    有些可以用bulk collect into 的~~
      

  4.   

    手写的,没有测试过,不知道有没有语法错误
    declare
    i number;
    begin
    for i in 1..100000 loop
    insert into .....;
    if mod((sql%rowcount),5000) = 0 then
    commit;
    end if;
    end loop;
    exception 
    when others then
    if sql%rowcount > 0 then
    rollback;
    end if;
    dbms_output.put_line('执行失败');
    end;
      

  5.   

    declare @i int
    set @i:=1
    while @i<=20000 loop
    begin
    insert into dbo.SYS_LOG(F_ID,F_NAME,F_DELETEFLAG) values(@i,'系统管理员',0)
    i:=i+1
    commentend loop
    end
      

  6.   

    用存储过程实现:
    create or replace procedure insert_proc as 
    begin
    for i in 1.. 100000 loop
    insert into dbo.SYS_LOG(F_ID,F_NAME,F_DELETEFLAG) values(@i,'系统管理员',0)
    end loop;
    commit;
    end;