不管是开发还是测试,工作中经常需要去批量新增测试数据,但是大量数据的新增速度有时候让我们苦不堪言,下面通过两种方式完成oracle数据的批量新增,比较两种方式的效率。
第一种方式:采用工具导入sql文件
以10w条数据为例,通过java程序生成insert语句,采用sqlplus进行导入
1、通过简单的JAVA程序生成sql脚本
public classGenerateSQLFile {public static void main(String[] args) throwsException {
File file= new File("d:" + File.separator + "data.sql");
OutputStream out= new FileOutputStream(file, true);for (int i = 1; i <= 100000; i++) {
String str= "insert into t_test(id,name) values(" +i+ ",'hello world" + i + "');\r\n";byte b[] =str.getBytes();
out.write(b);
}
out.close();
}
}
执行程序,生成的sql脚本如下所示:
insert into t_test_1(id,name) values(1,'hello world1');
insert into t_test_1