{"id":887,"date":"2017-10-05T14:00:41","date_gmt":"2017-10-05T07:00:41","guid":{"rendered":"https:\/\/oracletutorial.com\/?page_id=887"},"modified":"2025-05-11T19:48:31","modified_gmt":"2025-05-12T02:48:31","slug":"oracle-insert-all","status":"publish","type":"page","link":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/","title":{"rendered":"Oracle INSERT ALL Statement"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the Oracle <code>INSERT ALL<\/code> statement to insert multiple rows into a table or multiple tables.<\/p>\n\n\n\n<p class=\"note\">If you use Oracle 19c or later, you can use the <a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert\/#inserting-multiple-rows\" target=\"_blank\" rel=\"noreferrer noopener\">standard SQL INSERT statement to insert multiple rows<\/a> into a table.<\/p>\n\n\n\n<p>In the previous tutorial, you have learned <a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert\/\">how to insert a row into a table<\/a>. However, sometimes, you may want to insert multiple rows into a table or multiple tables. In this case, you use the Oracle <code>INSERT ALL<\/code> statement, which is also referred to as a <strong>multitable insert statement<\/strong>.<\/p>\n\n\n\n<p>Oracle provides you with two types of multitable insert statements: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>unconditional<\/li>\n\n\n\n<li>conditional<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='unconditional-oracle-insert-all-statement'>Unconditional Oracle INSERT ALL statement <a href=\"#unconditional-oracle-insert-all-statement\" class=\"anchor\" id=\"unconditional-oracle-insert-all-statement\" title=\"Anchor for Unconditional Oracle INSERT ALL statement\">#<\/a><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id='insert-multiple-rows-into-a-table'>Insert multiple rows into a table <a href=\"#insert-multiple-rows-into-a-table\" class=\"anchor\" id=\"insert-multiple-rows-into-a-table\" title=\"Anchor for Insert multiple rows into a table\">#<\/a><\/h3>\n\n\n\n<p>To insert multiple rows into a table, you use the following Oracle <code>INSERT ALL<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">ALL<\/span>\n    <span class=\"hljs-keyword\">INTO<\/span> table_name(col1,col2,col3) <span class=\"hljs-keyword\">VALUES<\/span>(val1,val2, val3)\n    <span class=\"hljs-keyword\">INTO<\/span> table_name(col1,col2,col3) <span class=\"hljs-keyword\">VALUES<\/span>(val4,val5, val6)\n    <span class=\"hljs-keyword\">INTO<\/span> table_name(col1,col2,col3) <span class=\"hljs-keyword\">VALUES<\/span>(val7,val8, val9)\nSubquery;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this statement, each value expression <code>val1<\/code>, <code>val2<\/code>, or <code>val3<\/code> must refer to a column returned by the select list of the <a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-subquery\/\">subquery<\/a>.<\/p>\n\n\n\n<p>If you want to use literal values instead of the values returned by the subquery, you use the following subquery:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> dual;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following example demonstrates how to insert multiple rows into a table.<\/p>\n\n\n\n<p>First, <a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-create-table\/\">create a new table<\/a> named <code>fruits<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> fruits (\n    fruit_name <span class=\"hljs-built_in\">VARCHAR2<\/span>(<span class=\"hljs-number\">100<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n    color <span class=\"hljs-built_in\">VARCHAR2<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, use the <code>INSERT ALL<\/code> statement to insert rows into the <code>fruits<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">ALL<\/span> \n    <span class=\"hljs-keyword\">INTO<\/span> fruits(fruit_name, color)\n    <span class=\"hljs-keyword\">VALUES<\/span> (<span class=\"hljs-string\">'Apple'<\/span>,<span class=\"hljs-string\">'Red'<\/span>) \n\n    <span class=\"hljs-keyword\">INTO<\/span> fruits(fruit_name, color)\n    <span class=\"hljs-keyword\">VALUES<\/span> (<span class=\"hljs-string\">'Orange'<\/span>,<span class=\"hljs-string\">'Orange'<\/span>) \n\n    <span class=\"hljs-keyword\">INTO<\/span> fruits(fruit_name, color)\n    <span class=\"hljs-keyword\">VALUES<\/span> (<span class=\"hljs-string\">'Banana'<\/span>,<span class=\"hljs-string\">'Yellow'<\/span>)\n<span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-number\">1<\/span> <span class=\"hljs-keyword\">FROM<\/span> dual;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, query data from the <code>fruits<\/code> table to verify the insertion:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> \n    *\n<span class=\"hljs-keyword\">FROM<\/span> \n    fruits;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"138\" height=\"80\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/10\/Oracle-INSERT-ALL-statement-example.png\" alt=\"Oracle INSERT ALL statement example\" class=\"wp-image-888\" title=\"Oracle INSERT ALL statement example\"\/><\/figure>\n\n\n\n<p>The output indicates that three rows were inserted into the <code>fruits<\/code> table successfully as expected.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='insert-multiple-rows-into-multiple-tables'>Insert multiple rows into multiple tables <a href=\"#insert-multiple-rows-into-multiple-tables\" class=\"anchor\" id=\"insert-multiple-rows-into-multiple-tables\" title=\"Anchor for Insert multiple rows into multiple tables\">#<\/a><\/h3>\n\n\n\n<p>Besides inserting multiple rows into a table, you can use the <code>INSERT ALL<\/code> statement to insert multiple rows into multiple tables.<\/p>\n\n\n\n<p>Here&#8217;s the syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">ALL<\/span>\n    <span class=\"hljs-keyword\">INTO<\/span> table_name1(col1,col2,col3) <span class=\"hljs-keyword\">VALUES<\/span>(val1,val2, val3)\n    <span class=\"hljs-keyword\">INTO<\/span> table_name2(col1,col2,col3) <span class=\"hljs-keyword\">VALUES<\/span>(val4,val5, val6)\n    <span class=\"hljs-keyword\">INTO<\/span> table_name3(col1,col2,col3) <span class=\"hljs-keyword\">VALUES<\/span>(val7,val8, val9)\nSubquery;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='conditional-oracle-insert-all-statement'>Conditional Oracle INSERT ALL Statement <a href=\"#conditional-oracle-insert-all-statement\" class=\"anchor\" id=\"conditional-oracle-insert-all-statement\" title=\"Anchor for Conditional Oracle INSERT ALL Statement\">#<\/a><\/h2>\n\n\n\n<p>The conditional multitable insert statement allows you to insert rows into tables based on specified conditions.<\/p>\n\n\n\n<p>The following shows the syntax of the conditional multitable insert statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> &#91; <span class=\"hljs-keyword\">ALL<\/span> | <span class=\"hljs-keyword\">FIRST<\/span> ]\n    <span class=\"hljs-keyword\">WHEN<\/span> condition1 <span class=\"hljs-keyword\">THEN<\/span>\n        <span class=\"hljs-keyword\">INTO<\/span> table_1 (column_list ) <span class=\"hljs-keyword\">VALUES<\/span> (value_list)\n    <span class=\"hljs-keyword\">WHEN<\/span> condition2 <span class=\"hljs-keyword\">THEN<\/span> \n        <span class=\"hljs-keyword\">INTO<\/span> table_2(column_list ) <span class=\"hljs-keyword\">VALUES<\/span> (value_list)\n    <span class=\"hljs-keyword\">ELSE<\/span>\n        <span class=\"hljs-keyword\">INTO<\/span> table_3(column_list ) <span class=\"hljs-keyword\">VALUES<\/span> (value_list)\nSubquery\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you specify the <code>ALL<\/code> keyword, then Oracle evaluates each condition in the <code>WHEN<\/code> clauses. If a condition evaluates to true, Oracle executes the corresponding <code>INTO<\/code> clause.<\/p>\n\n\n\n<p>However, when you specify <code>FIRST<\/code> keyword, for each row returned by the subquery, Oracle evaluates each condition in the <code>WHEN<\/code> clause from top to bottom. If Oracle finds a condition that evaluates to true, it executes the corresponding <code>INTO<\/code> clause and skips subsequent <code>WHEN<\/code> clauses for the given row.<\/p>\n\n\n\n<p>Note that a single conditional multitable insert statement can have up to 127 <code>WHEN<\/code> clauses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='conditional-oracle-insert-all-example'>Conditional Oracle INSERT ALL example <a href=\"#conditional-oracle-insert-all-example\" class=\"anchor\" id=\"conditional-oracle-insert-all-example\" title=\"Anchor for Conditional Oracle INSERT ALL example\">#<\/a><\/h3>\n\n\n\n<p>First, create three tables: <code>small_orders<\/code>, <code>medium_orders<\/code>, and <code>big_orders<\/code> with the same structures:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> small_orders (\n    order_id <span class=\"hljs-built_in\">NUMBER<\/span>(<span class=\"hljs-number\">12<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    customer_id <span class=\"hljs-built_in\">NUMBER<\/span>(<span class=\"hljs-number\">6<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    amount <span class=\"hljs-built_in\">NUMBER<\/span>(<span class=\"hljs-number\">8<\/span>,<span class=\"hljs-number\">2<\/span>) \n);\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> medium_orders <span class=\"hljs-keyword\">AS<\/span>\n<span class=\"hljs-keyword\">SELECT<\/span> *\n<span class=\"hljs-keyword\">FROM<\/span> small_orders;\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> big_orders <span class=\"hljs-keyword\">AS<\/span>\n<span class=\"hljs-keyword\">SELECT<\/span> *\n<span class=\"hljs-keyword\">FROM<\/span> small_orders;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, insert order data into the three tables <code>small_orders<\/code>, <code>medium_orders<\/code>, and <code>big_orders<\/code> based on orders&#8217; amounts:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">ALL<\/span>\n   <span class=\"hljs-keyword\">WHEN<\/span> amount &lt; <span class=\"hljs-number\">10000<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n      <span class=\"hljs-keyword\">INTO<\/span> small_orders\n   <span class=\"hljs-keyword\">WHEN<\/span> amount &gt;= <span class=\"hljs-number\">10000<\/span> <span class=\"hljs-keyword\">AND<\/span> amount &lt;= <span class=\"hljs-number\">30000<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n      <span class=\"hljs-keyword\">INTO<\/span> medium_orders\n   <span class=\"hljs-keyword\">WHEN<\/span> amount &gt; <span class=\"hljs-number\">30000<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n      <span class=\"hljs-keyword\">INTO<\/span> big_orders\n      \n  <span class=\"hljs-keyword\">SELECT<\/span> order_id,\n         customer_id,\n         (quantity * unit_price) amount\n  <span class=\"hljs-keyword\">FROM<\/span> orders\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> order_items <span class=\"hljs-keyword\">USING<\/span>(order_id);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Alternatively, you can achieve the same result by using the <code>ELSE<\/code> clause in place of the insert into the <code>big_orders<\/code> tables as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">ALL<\/span>\n   <span class=\"hljs-keyword\">WHEN<\/span> amount &lt; <span class=\"hljs-number\">10000<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n      <span class=\"hljs-keyword\">INTO<\/span> small_orders\n   <span class=\"hljs-keyword\">WHEN<\/span> amount &gt;= <span class=\"hljs-number\">10000<\/span> <span class=\"hljs-keyword\">AND<\/span> amount &lt;= <span class=\"hljs-number\">30000<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n      <span class=\"hljs-keyword\">INTO<\/span> medium_orders\n   <span class=\"hljs-keyword\">ELSE<\/span>\n      <span class=\"hljs-keyword\">INTO<\/span> big_orders\n  <span class=\"hljs-keyword\">SELECT<\/span> order_id,\n         customer_id,\n         (quantity * unit_price) amount\n  <span class=\"hljs-keyword\">FROM<\/span> orders\n  <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> order_items <span class=\"hljs-keyword\">USING<\/span>(order_id);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, retrieve data from small_orders:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  *\n<span class=\"hljs-keyword\">FROM<\/span>\n  small_orders\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n  amount <span class=\"hljs-keyword\">DESC<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">  ORDER_ID CUSTOMER_ID     AMOUNT\n<span class=\"hljs-comment\">---------- ----------- ----------<\/span>\n        36          51    9983.76\n        36          51    9983.76\n        30          45    9915.63\n        30          45    9915.63\n        42          56    9822.08\n        42          56    9822.08<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>medium_orders:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">  ORDER_ID CUSTOMER_ID     AMOUNT\n<span class=\"hljs-comment\">---------- ----------- ----------<\/span>\n        40          55   29876.04\n        40          55   29876.04\n        91           9    29806.5\n        91           9    29806.5\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">  ORDER_ID CUSTOMER_ID     AMOUNT\n<span class=\"hljs-comment\">---------- ----------- ----------<\/span>\n        40          55   29876.04\n        40          55   29876.04\n        91           9    29806.5\n        91           9    29806.5\n        61           2   29676.58\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>big_orders<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  *\n<span class=\"hljs-keyword\">FROM<\/span>\n  big_orders\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span>\n  amount;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">  ORDER_ID CUSTOMER_ID     AMOUNT\n<span class=\"hljs-comment\">---------- ----------- ----------<\/span>\n        27          43   30036.45\n        27          43   30036.45\n        45          57   30183.85\n        45          57   30183.85\n        34          49      30199\n...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='conditional-oracle-insert-first-example'>Conditional Oracle INSERT FIRST example <a href=\"#conditional-oracle-insert-first-example\" class=\"anchor\" id=\"conditional-oracle-insert-first-example\" title=\"Anchor for Conditional Oracle INSERT FIRST example\">#<\/a><\/h3>\n\n\n\n<p>The following example illustrates how to use a conditional insert first statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">FIRST<\/span>\n    <span class=\"hljs-keyword\">WHEN<\/span> amount &gt; <span class=\"hljs-number\">30000<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n        <span class=\"hljs-keyword\">INTO<\/span> big_orders\n    <span class=\"hljs-keyword\">WHEN<\/span> amount &gt;= <span class=\"hljs-number\">10000<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n        <span class=\"hljs-keyword\">INTO<\/span> medium_orders\n    <span class=\"hljs-keyword\">WHEN<\/span> amount &gt; <span class=\"hljs-number\">0<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n        <span class=\"hljs-keyword\">INTO<\/span> small_orders\n <span class=\"hljs-keyword\">SELECT<\/span> order_id,\n         customer_id,\n         (quantity * unit_price) amount\n <span class=\"hljs-keyword\">FROM<\/span> orders\n <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> order_items <span class=\"hljs-keyword\">USING<\/span>(order_id);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This statement will not make any sense in an <code>INSERT ALL<\/code> because the orders whose amount greater than <code>30,000<\/code> would have ended up being inserted into the three tables.<\/p>\n\n\n\n<p>However, with <code>INSERT FIRST<\/code>, for each row returned by the subquery Oracle will evaluate each <code>WHEN<\/code> condition from top to bottom:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, if the amount of the order is greater than <code>30,000<\/code>, Oracle inserts data into the <code>big_tables<\/code> and ignores the subsequent <code>WHEN<\/code> conditions.<\/li>\n\n\n\n<li>Second, if the first evaluation is <code>false<\/code> and the <code>amount<\/code> is greater than or equal to <code>10,000<\/code>, Oracle inserts data into the <code>medium_tables<\/code> and it also skips evaluating the third <code>WHEN<\/code> clause.<\/li>\n\n\n\n<li>Third, if the first two <code>WHEN<\/code> conditions evaluate false, Oracle executes the <code>INTO<\/code> clause in the <code>ELSE<\/code> clause which inserts data into the <code>small_orders<\/code> table.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='oracle-insert-all-restrictions'>Oracle INSERT ALL restrictions <a href=\"#oracle-insert-all-restrictions\" class=\"anchor\" id=\"oracle-insert-all-restrictions\" title=\"Anchor for Oracle INSERT ALL restrictions\">#<\/a><\/h2>\n\n\n\n<p>The Oracle multitable insert statement is subject to the following main restrictions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It can be used to insert data into tables only, not <a href=\"https:\/\/www.oracletutorial.com\/oracle-view\/\">views<\/a> or materialized views.<\/li>\n\n\n\n<li>It cannot be used to insert data into remote tables.<\/li>\n\n\n\n<li>The number of columns in all the <code>INSERT INTO<\/code> clauses must not exceed 999.<\/li>\n\n\n\n<li>A table collection expression cannot be used in a multitable insert statement.<\/li>\n\n\n\n<li>The subquery of the multitable insert statement cannot use a <a href=\"https:\/\/www.oracletutorial.com\/oracle-sequence\/\">sequence<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the Oracle <code>INSERT ALL<\/code> statement to insert multiple rows into a table or multiple tables.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"887\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/\"\n\t\t\t\tdata-post-title=\"Oracle INSERT ALL Statement\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"887\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/\"\n\t\t\t\tdata-post-title=\"Oracle INSERT ALL Statement\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows you how to use the Oracle INSERT ALL statement to insert multiple rows into a table or multiple tables.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":386,"menu_order":52,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-887","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Oracle INSERT ALL Statement<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the Oracle INSERT ALL statement to insert multiple rows into a table or multiple tables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle INSERT ALL Statement\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the Oracle INSERT ALL statement to insert multiple rows into a table or multiple tables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/\" \/>\n<meta property=\"og:site_name\" content=\"Oracle Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-12T02:48:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/10\/Oracle-INSERT-ALL-statement-example.png\" \/>\n\t<meta property=\"og:image:width\" content=\"138\" \/>\n\t<meta property=\"og:image:height\" content=\"80\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/\",\"name\":\"Oracle INSERT ALL Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/10\\\/Oracle-INSERT-ALL-statement-example.png\",\"datePublished\":\"2017-10-05T07:00:41+00:00\",\"dateModified\":\"2025-05-12T02:48:31+00:00\",\"description\":\"This tutorial shows you how to use the Oracle INSERT ALL statement to insert multiple rows into a table or multiple tables.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/10\\\/Oracle-INSERT-ALL-statement-example.png\",\"contentUrl\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/10\\\/Oracle-INSERT-ALL-statement-example.png\",\"width\":138,\"height\":80,\"caption\":\"Oracle INSERT ALL statement example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/oracle-insert-all\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.oracletutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oracle Basics\",\"item\":\"https:\\\/\\\/www.oracletutorial.com\\\/oracle-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Oracle INSERT ALL Statement\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/\",\"name\":\"Oracle Tutorial\",\"description\":\"Oracle Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.oracletutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Oracle INSERT ALL Statement","description":"This tutorial shows you how to use the Oracle INSERT ALL statement to insert multiple rows into a table or multiple tables.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/","og_locale":"en_US","og_type":"article","og_title":"Oracle INSERT ALL Statement","og_description":"This tutorial shows you how to use the Oracle INSERT ALL statement to insert multiple rows into a table or multiple tables.","og_url":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/","og_site_name":"Oracle Tutorial","article_modified_time":"2025-05-12T02:48:31+00:00","og_image":[{"width":138,"height":80,"url":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/10\/Oracle-INSERT-ALL-statement-example.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/","url":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/","name":"Oracle INSERT ALL Statement","isPartOf":{"@id":"https:\/\/www.oracletutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/#primaryimage"},"image":{"@id":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/#primaryimage"},"thumbnailUrl":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/10\/Oracle-INSERT-ALL-statement-example.png","datePublished":"2017-10-05T07:00:41+00:00","dateModified":"2025-05-12T02:48:31+00:00","description":"This tutorial shows you how to use the Oracle INSERT ALL statement to insert multiple rows into a table or multiple tables.","breadcrumb":{"@id":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/#primaryimage","url":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/10\/Oracle-INSERT-ALL-statement-example.png","contentUrl":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/10\/Oracle-INSERT-ALL-statement-example.png","width":138,"height":80,"caption":"Oracle INSERT ALL statement example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-insert-all\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.oracletutorial.com\/"},{"@type":"ListItem","position":2,"name":"Oracle Basics","item":"https:\/\/www.oracletutorial.com\/oracle-basics\/"},{"@type":"ListItem","position":3,"name":"Oracle INSERT ALL Statement"}]},{"@type":"WebSite","@id":"https:\/\/www.oracletutorial.com\/#website","url":"https:\/\/www.oracletutorial.com\/","name":"Oracle Tutorial","description":"Oracle Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.oracletutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/comments?post=887"}],"version-history":[{"count":0,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/887\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/386"}],"wp:attachment":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/media?parent=887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}