Comparison of Oracle Insert AND bulk Insert speed

Source: Internet
Author: User
Tags bulk insert

After a long period of contact with Oracle Insert AND bulk Insert, I compared their execution efficiency. I would like to share with you the following information.

Test the insert speed of java with The bulk Insert speed after 9i. The result shows that the Insert speed through bulk is quite fast.

100000 records

Insert, --------------- 93 seconds

Bulk Insert ------------- 0.441 seconds

Environment:

Oracle 10.2.0.3 Windows 2000 Server

Java

Code:

 
 
  1. SQL> desc a  
  2. Name Type Nullable Default Comments   
  3. ---- ------------ -------- ------- --------   
  4. ID INTEGER Y   
  5. NAME VARCHAR2(20) Y   

Bulk Insert type and Process

 
 
  1. create or replace type i_table is table of number(10);  
  2. create or replace type v_table is table of varchar2(10);  
  3. create or replace procedure pro_forall_insert(v_1 i_table,v_2 v_table)  
  4. as  
  5. c integer;  
  6. begin  
  7. forall i in 1.. v_1.count   
  8. insert into a values(v_1(i),v_2(i));  
  9. end;  
  10.  

Java code for testing:

 
 
  1. import java.io.*;  
  2. import java.sql.*;  
  3. import java.util.*;  
  4. import javax.naming.Context;  
  5. import javax.naming.InitialContext;  
  6. import javax.naming.*;  
  7. import oracle.jdbc.OracleTypes;  
  8. import oracle.sql.*;  
  9. import oracle.sql.ARRAY;  
  10. import oracle.sql.ArrayDescriptor;  
  11. import oracle.sql.STRUCT;  
  12. import oracle.sql.StructDescriptor;  
  13. import java.sql.Connection;  
  14. import java.sql.DriverManager;  
  15. import oracle.jdbc.OracleCallableStatement;  
  16.  
  17. public class testOracle {  
  18. public testOracle() {  
  19. Connection oraCon = null;  
  20. PreparedStatement ps = null;  
  21. Statement st = null;  
  22. ResultSet rs = null;  
  23. try {  
  24. try {  
  25. Class.forName("oracle.jdbc.driver.OracleDriver");  
  26. } catch (ClassNotFoundException ex) {}  
  27. oraCon = DriverManager.getConnection("jdbc:oracle:thin:@192.168.15.234:1521:ora10g", "imcs","imcs");  
  28. oraCon.setAutoCommit(false);  
  29. } catch (SQLException ex) {  
  30. ex.printStackTrace();  
  31. }  
  32. CallableStatement cstmt = null;  
  33. oracle.sql.ArrayDescriptor a = null;  
  34. oracle.sql.ArrayDescriptor b = null;  
  35. if (1 == 1 )  
  36. {  
  37. Object[] s1 = new Object[100000];  
  38. Object[] s2 = new Object[100000];  
  39. for (int i = 0; i < 100000; i++) {  
  40. s1[i] = new Integer(1);  
  41. s2[i] = new String("aaa").concat(String.valueOf(i));  
  42. }  
  43. try {  
  44. a = oracle.sql.ArrayDescriptor.createDescriptor("I_TABLE", oraCon);  
  45. b = oracle.sql.ArrayDescriptor.createDescriptor("V_TABLE", oraCon);  
  46. ARRAY a_test = new ARRAY(a, oraCon, s1);  
  47. ARRAY b_test = new ARRAY(b, oraCon, s2);  
  48. cstmt = oraCon.prepareCall("{ call pro_forall_insert(?,?) }");  
  49. cstmt.setObject(1, a_test);  
  50. cstmt.setObject(2, b_test);  
  51. long aaaa = System.currentTimeMillis();  
  52. System.out.println(System.currentTimeMillis());  
  53. cstmt.execute();  
  54. oraCon.commit();  
  55. System.out.println(System.currentTimeMillis()-aaaa);  
  56.  catch (Exception e) {  
  57. e.printStackTrace();  
  58. }  
  59. }  
  60. else  
  61. {  
  62. try  
  63. {  
  64. PreparedStatement oraPs = null;  
  65. String oraInsertSql =  
  66. "insert into a values(?,?)";  
  67. oraPs = oraCon.prepareStatement(oraInsertSql);  
  68. long aaaa = System.currentTimeMillis();  
  69. System.out.println(System.currentTimeMillis());  
  70. for (int i = 0; i < 100000; i++)  
  71. {  
  72. oraPs.setInt(1,i);  
  73. oraPs.setString(2, new String("aaa").concat(String.valueOf(i)));  
  74. oraPs.executeUpdate();   
  75. }  
  76. oraCon.commit();  
  77. System.out.println(System.currentTimeMillis()-aaaa);  
  78. }  
  79. catch (SQLException ex)  
  80. {  
  81. System.out.print("dddddd");  
  82. System.out.print(ex.getMessage());  
  83. }  
  84. }  
  85. try {  
  86. jbInit();  
  87. } catch (Exception ex) {  
  88. ex.printStackTrace();  
  89. }  
  90. }  
  91. public static void main(String args[]) {  
  92. testOracle a = new testOracle();  
  93. }  
  94. private void jbInit() throws Exception {  
  95. }  
  96. };  
  97.  
  1. Code required to modify the Oracle storage process
  2. Summary of Oracle stored procedures
  3. Code for implementing the Oracle storage process
  4. In-depth high-performance dynamic Oracle SQL Development
  5. Analysis of Oracle SQL optimization rules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.