Oracle Insert Statement

In Oracle, INSERT statement is used to add a single record or multiple records into the table.

Syntax: (Inserting a single record using the Values keyword):

  1.  INSERT INTO table  
  2. (column1, column2, ... column_n )  
  3. VALUES  
  4. (expression1, expression2, ... expression_n );   


Syntax: (Inserting multiple records using a SELECT statement):

  1. INSERT INTO table  
  2. (column1, column2, ... column_n )  
  3. SELECT expression1, expression2, ... expression_n  
  4. FROM source_table  
  5. WHERE conditions;   



1) table: The table to insert the records into.

2) column1, column2, ... column_n:

The columns in the table to insert values.

3) expression1, expression2, ... expression_n:

The values to assign to the columns in the table. So column1 would be assigned the value of expression1, column2 would be assigned the value of expression2, and so on.

4) source_table:

The source table when inserting data from another table.

5) conditions:

The conditions that must be met for the records to be inserted.

Oracle Insert Example: By VALUE keyword

It is the simplest way to insert elements to a database by using VALUE keyword.

See this example:

Consider here the already created suppliers table. Add a new row where the value of supplier_id is 23 and supplier_name is Flipkart.

See this example:

  1. INSERT INTO suppliers  
  2. (supplier_id, supplier_name)  
  3. VALUES  
  4. (50, 'Flipkart');  



1 row(s) inserted.
0.02 seconds

Oracle Insert Example: By SELECT statement

This method is used for more complicated cases of insertion. In this method insertion is done by SELECT statement. This method is used to insert multiple elements.

See this example:

In this method, we insert values to the "suppliers" table from "customers" table. Both tables are already created with their respective columns.

Execute this query:

  1. INSERT INTO suppliers  
  2. (supplier_id, supplier_name)  
  3. SELECT age, address  
  4. FROM customers  
  5. WHERE age > 20;  



4 row(s) inserted.

0.00 seconds

You can even check the number of rows that you want to insert by following statement:

  1. SELECT count(*)  
  2. FROM customers  
  3. WHERE age > 20;