Home >Database >Mysql Tutorial >How to Efficiently Perform Multi-Row Inserts in Oracle?
Unlike MySQL single statement multi-row insertion, Oracle database does not support this direct method. But we can achieve similar functionality in several ways:
Use INSERT ALL syntax (before Oracle 23c)
In versions prior to Oracle 23c, you can use the INSERT ALL
syntax for multi-row insertion. The following example demonstrates how to use INSERT ALL
to insert data into the TMP_DIM_EXCH_RT
table:
<code class="language-sql">INSERT ALL INTO TMP_DIM_EXCH_RT (EXCH_WH_KEY, EXCH_NAT_KEY, EXCH_DATE, EXCH_RATE, FROM_CURCY_CD, TO_CURCY_CD, EXCH_EFF_DATE, EXCH_EFF_END_DATE, EXCH_LAST_UPDATED_DATE) VALUES (1, 1, '28-AUG-2008', 109.49, 'USD', 'JPY', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'), (2, 1, '28-AUG-2008', .54, 'USD', 'GBP', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'), (3, 1, '28-AUG-2008', 1.05, 'USD', 'CAD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'), (4, 1, '28-AUG-2008', .68, 'USD', 'EUR', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'), (5, 1, '28-AUG-2008', 1.16, 'USD', 'AUD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'), (6, 1, '28-AUG-2008', 7.81, 'USD', 'HKD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008') SELECT 1 FROM DUAL;</code>
Oracle 23c simplified syntax
Oracle 23c introduces a simplified multi-row insert syntax:
<code class="language-sql">INSERT INTO t(col1, col2, col3) VALUES ('val1_1', 'val1_2', 'val1_3'), ('val2_1', 'val2_2', 'val2_3'), ('val3_1', 'val3_2', 'val3_3');</code>
This syntax allows multiple rows to be inserted using a single statement.
Performance Considerations
For large data sets, Oracle 23c's simplified syntax is more efficient than the INSERT ALL
approach. In order to optimize performance, it is recommended that the number of rows inserted at a time should not exceed about 1,000 rows.
The above is the detailed content of How to Efficiently Perform Multi-Row Inserts in Oracle?. For more information, please follow other related articles on the PHP Chinese website!