oracle中怎么插入多条数据

如题所述

第1个回答  2018-03-31
1、采用insert into values 语句插入一条,写很多条语句即可多条数据,这种主要针对于离散值以及一些基础信息的录入,如:insert into test(xh,mc) values('123','测试');
如果插入的数据有规律,可利用for、loop循环插入,主要用于批量生成测试数据
begin
for i in 1 .. 100 loop
insert into test(xh,mc) values(i||'','测试');
end loop;
end ;。
2、采用insert into selct from 语句来一次性插入一个集合,这种主要依据于要插入的数据源已经存储于数据库对象中,或者利用dual虚表来构造数据,经过加工后写入一个集合。
insert into test (xh,mx) select '123','测试' from dual;
3、采用plsql等工具、或者oracle的imp、impdp命令来导入,这种主要用数据库与数据库之间的大批量数据导入,导入的数据格式为plsql的pde、oracle的dmp等。dmp文件可使用
table_exists_action参数控制导入动作:replace替换原表,truncate清除原表数据再导入,append增量导入数据,当然impdp数据泵的导入要依赖于directory路径。
impdp 用户名/密码 dumpfile=123.dmp logfile=123.log directory=imp_dir tables=test table_exists_action=append
4、使用excel文件直接拷贝。这种主要用于要写入的数据已是excel文件或者行列分明的其它格式文件,每一列的值和表结构相对应,可直接打开表的行级锁,把数据拷贝进入。
打开行级锁方法:
select t.*,rowid from 表名 t where 1=2;
select * from 表名 where 1=2 for update;
直接把excel数据拷贝到表里
第2个回答  2016-06-17
1、采用insert into values 语句插入一条,写很多条语句即可多条数据,这种主要针对于离散值以及一些基础信息的录入,如:insert into test(xh,mc) values('123','测试');
如果插入的数据有规律,可利用for、loop循环插入,主要用于批量生成测试数据
begin
for i in 1 .. 100 loop
insert into test(xh,mc) values(i||'','测试');
end loop;
end ;。
2、采用insert into selct from 语句来一次性插入一个集合,这种主要依据于要插入的数据源已经存储于数据库对象中,或者利用dual虚表来构造数据,经过加工后写入一个集合。
insert into test (xh,mx) select '123','测试' from dual;
3、采用plsql等工具、或者oracle的imp、impdp命令来导入,这种主要用数据库与数据库之间的大批量数据导入,导入的数据格式为plsql的pde、oracle的dmp等。dmp文件可使用
table_exists_action参数控制导入动作:replace替换原表,truncate清除原表数据再导入,append增量导入数据,当然impdp数据泵的导入要依赖于directory路径。
impdp 用户名/密码 dumpfile=123.dmp logfile=123.log directory=imp_dir tables=test table_exists_action=append
4、使用excel文件直接拷贝。这种主要用于要写入的数据已是excel文件或者行列分明的其它格式文件,每一列的值和表结构相对应,可直接打开表的行级锁,把数据拷贝进入。
打开行级锁方法:
select t.*,rowid from 表名 t where 1=2;
select * from 表名 where 1=2 for update;
直接把excel数据拷贝到表里