Home > Database > Mysql Tutorial > How Can I Efficiently Insert Multiple Rows into an Oracle Database?

How Can I Efficiently Insert Multiple Rows into an Oracle Database?

Linda Hamilton
Release: 2025-01-22 18:21:13
Original
746 people have browsed it

How Can I Efficiently Insert Multiple Rows into an Oracle Database?

Efficient batch insertion method of data in Oracle database

There are many ways to insert multiple rows of data into Oracle database. The batch insert method commonly used in MySQL is not directly supported in Oracle.

Use INSERT ALL statement

In Oracle, you can use the INSERT ALL statement for batch insertion. This statement contains multiple INTO clauses, each clause represents a row of data to be inserted. The statement ends with SELECT 1 FROM DUAL as a sign of the end of the insertion.

<code class="language-sql">INSERT ALL
   INTO t (col1, col2, col3) VALUES ('val1_1', 'val1_2', 'val1_3')
   INTO t (col1, col2, col3) VALUES ('val2_1', 'val2_2', 'val2_3')
   INTO t (col1, col2, col3) VALUES ('val3_1', 'val3_2', 'val3_3')
   .
   .
   .
SELECT 1 FROM DUAL;</code>
Copy after login

Oracle 23c simplified syntax

Oracle 23c introduces a simplified bulk insert syntax that eliminates the need for the INSERT ALL statement. Multiple rows of data can be inserted using a comma separated list like this:

<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>
Copy after login

Performance Considerations

For large amounts of data, performance issues must be considered. The new INSERT syntax in Oracle 23c is much faster than INSERT ALL and has comparable performance to the UNION ALL method. However, inserting more than about 1000 rows of data at a time causes parsing time to increase exponentially.

The above is the detailed content of How Can I Efficiently Insert Multiple Rows into an Oracle Database?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template