Oracle SQL: Insert Multiple Rows Into a Table
In this article
You can insert multiple rows into an Oracle table in one statement using either the multi-row INSERT ALL syntax or a single INSERT ... SELECT ... UNION ALL query. The INSERT ALL form is the most readable for a handful of literal rows and works in all supported Oracle Database versions; the UNION ALL form is a portable fallback when you need a single INSERT with a SELECT source. Both approaches are faster than running many separate single-row INSERT statements because they reduce round trips and parse overhead.
What You'll Need
- Access to an Oracle Database instance (any supported version, including Oracle Database Free, Express Edition, or a cloud instance).
- A user account with the
INSERTprivilege on the target table, or theINSERT ANY TABLEsystem privilege. - A SQL client such as SQL*Plus, SQL Developer, SQLcl, or any JDBC/ODBC-based tool that can run a script.
- The target table must already exist, and you need to know its column names, data types, and any
NOT NULLor check constraints.
Step-by-Step
- Connect to the database. Open your SQL client and connect as the schema owner or a user with insert rights. For example, in SQL*Plus run
CONNECT username/password@service_name. If you are using SQL Developer, create a connection and open a SQL Worksheet. - Confirm the table structure. Run
DESCRIBE your_table;(or queryUSER_TAB_COLUMNS) to list column names and data types. This prevents column-order mistakes and tells you which columns are mandatory. - Choose your insert style. Use
INSERT ALLfor literal values that are easy to read. UseINSERT ... SELECT ... UNION ALLif you are pulling rows from another query, or if your client or tool has trouble withINSERT ALL. Both are single statements and both are valid Oracle SQL. - Write the
INSERT ALLstatement. The pattern is:INSERT ALL, then oneINTO table (columns) VALUES (...)clause per row, then a finalSELECT * FROM dual;to satisfy Oracle's requirement thatINSERT ALLbe followed by a subquery. For example:
TheINSERT ALL INTO employees (employee_id, first_name, last_name, hire_date) VALUES (101, 'Alice', 'Nguyen', DATE '2024-01-15') INTO employees (employee_id, first_name, last_name, hire_date) VALUES (102, 'Ben', 'Okafor', DATE '2024-02-01') INTO employees (employee_id, first_name, last_name, hire_date) VALUES (103, 'Carla', 'Mendes', DATE '2024-03-10') SELECT * FROM dual;SELECT * FROM dualline is not optional: without it Oracle raises an error becauseINSERT ALLexpects a subquery source. - Or write the
UNION ALLform. This is a singleINSERTwhose source is a set ofSELECT ... FROM dualrows joined byUNION ALL:
This form works in every Oracle version and is easy to generate programmatically.INSERT INTO employees (employee_id, first_name, last_name, hire_date) SELECT 101, 'Alice', 'Nguyen', DATE '2024-01-15' FROM dual UNION ALL SELECT 102, 'Ben', 'Okafor', DATE '2024-02-01' FROM dual UNION ALL SELECT 103, 'Carla', 'Mendes', DATE '2024-03-10' FROM dual; - Run the statement. Execute it in your SQL client. Oracle reports the number of rows inserted (for example,
3 rows inserted.). If you are using SQL*Plus or SQLcl, end the statement with a semicolon and press Enter; in SQL Developer, use the Run Statement button (F9) or Run Script (F5) for scripts. - Commit the transaction. Oracle does not auto-commit by default. Run
COMMIT;to make the inserts permanent, orROLLBACK;if you spot a mistake. Many GUI clients have an auto-commit toggle; check its state before running large inserts. - Verify the rows. Query the table, for example
SELECT * FROM employees WHERE employee_id IN (101,102,103);, and confirm the values, dates, and nulls are as expected.
Common Mistakes
- Omitting the final
SELECTinINSERT ALL. Oracle requires a subquery after theINTOclauses;SELECT * FROM dualis the standard filler. - Forgetting to commit. The rows appear in your session but disappear for other users and after disconnect until you run
COMMIT. - Mismatched column counts or types. Each
INTO ... VALUESclause must supply values for exactly the listed columns, in the same order, with compatible data types. A string in aNUMBERcolumn fails at parse or execute time. - Using
INSERT ALLwith aVALUESclause that references a sequence incorrectly. If you need sequence values, callseq.NEXTVALonce per row; do not assume a single call populates all rows. - Exceeding the 1000-element
INlimit when verifying. Oracle limits anINlist to 1000 expressions; split larger checks or use a join. - Assuming
INSERT ALLis atomic per row. The statement is one transaction; a failure rolls back the whole statement unless you handle errors withLOG ERRORS.
Tips
- Use the
DATE 'YYYY-MM-DD'literal syntax for dates to avoidNLS_DATE_FORMATsurprises. - For large batches (thousands of rows), prefer
INSERT ... SELECTfrom an external table, a staging table, or use SQL*Loader; multi-rowINSERT ALLis convenient but not a bulk loader. - Add the
LOG ERRORS INTO err$_table REJECT LIMIT UNLIMITEDclause (after creating an error log table withDBMS_ERRLOG.CREATE_ERROR_LOG) to capture bad rows without failing the whole statement. - Wrap the statement in a transaction and validate with a
SELECT COUNT(*)before committing. - Keep column lists explicit in every
INTOclause; relying on positional inserts breaks when the table gains a column.
Troubleshooting
- ORA-00933: SQL command not properly ended. Usually a missing
SELECT * FROM dualafterINSERT ALL, or a stray semicolon inside the statement. - ORA-00947: not enough values. The number of values does not match the number of columns in an
INTOclause. Recount both lists. - ORA-01861: literal does not match format string. A date or timestamp string is being converted implicitly. Use
DATE '...'orTO_DATEwith an explicit format. - ORA-00001: unique constraint violated. One of the rows duplicates an existing key. Remove or update the duplicate, or use a merge strategy.
- Rows inserted but not visible to others. You have not committed. Run
COMMIT;in the same session. - Statement hangs or runs long. Check for locks on the table from another session (
V$LOCK,V$SESSION) and confirm you are not inserting into a table with a long-running trigger.
Frequently Asked Questions
Can I insert multiple rows with a single INSERT in Oracle?
Yes. Use INSERT ALL ... SELECT * FROM dual or INSERT INTO ... SELECT ... UNION ALL .... Both are single statements and both are standard Oracle SQL.
Is there a limit on how many rows INSERT ALL can handle?
There is no small hard limit like 1000; the practical limit is memory and undo. For very large batches, use SQL*Loader, external tables, or INSERT ... SELECT from a staging table.
Why do I need SELECT * FROM dual at the end of INSERT ALL?
Oracle's grammar requires INSERT ALL to be followed by a subquery that supplies the source rows. SELECT * FROM dual returns one row and satisfies the syntax without adding data.
Does INSERT ALL commit automatically?
No. Oracle does not auto-commit DML by default. You must run COMMIT to persist the rows; otherwise a rollback or disconnect discards them.
Can I use a sequence with INSERT ALL?
Yes, but call sequence_name.NEXTVAL in each INTO clause where you need a new value. A single call does not automatically populate every row.
What is the difference between INSERT ALL and INSERT FIRST?
INSERT ALL inserts into every INTO clause whose condition is true (or unconditionally). INSERT FIRST evaluates conditions in order and inserts only into the first matching clause, which is useful for conditional routing.