oracle的批量插入方式有多种,以下列举三种常用写法
方式1
insert all
into oracle_table ( id, code ) values( 1 , '1' )
into oracle_table ( id, code ) values( 2 , '2' )
into oracle_table ( id, code ) values( 3 , '3' )
into oracle_table ( id, code ) values( 4 , '4' )
select 1 from dual ;
此种方式,看起来比较简洁
方式2
insert into oracle_table (id,code)
select id,code from (
select 1 as id, '1' as code from dual
union all
select 1 as id, '1' as code from dual
union all
select 1 as id, '1' as code from dual
union all
select 1 as id, '1' as code from dual
) ;
使用union all 拼接批量数据,然后使用insert into 方法插入拼接好的数据
方式3
begin
insert into oracle_table ( id, code ) values( 1 , '1' );
insert into oracle_table ( id, code ) values( 2 , '2' );
insert into oracle_table ( id, code ) values( 3 , '3' );
insert into oracle_table ( id, code ) values( 4 , '4' );
end;
用语句块来执行批量语句