Oracle – 40 – SELECT, INSERT, INSERT ALL, DELETE, UPDATE and TRUCATE

In Oracle SQL, the SELECT, INSERT, INSERT ALL, DELETE, UPDATE, and TRUNCATE statements are used for querying and manipulating data in database tables. Here’s a brief description of each of these SQL statements:

1. SELECT Statement:

  • Purpose: The SELECT statement is used to retrieve data from one or more tables or views in the database.
  • Syntax: SELECT column1, column2, ... FROM table_name WHERE condition;
  • Use Cases: SELECT is used for querying data, filtering rows, joining tables, aggregating data using functions, and returning the result set to the user or application.

2. INSERT Statement:

  • Purpose: The INSERT statement is used to add new rows of data into a table.
  • Syntax: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
  • Use Cases: INSERT is used when you want to add new records to a table. You specify the target table, the columns to insert data into, and the values for those columns.

3. INSERT ALL Statement:

  • Purpose: INSERT ALL is an extension of the INSERT statement that allows you to insert multiple rows into one or more tables in a single SQL statement.
  • Syntax: INSERT ALL INTO table1 (column1, column2, ...) VALUES (value1, value2, ...) INTO table2 (column1, column2, ...) VALUES (value1, value2, ...) ... SELECT * FROM dual;
  • Use Cases: INSERT ALL is used when you need to insert data into multiple tables simultaneously, typically as part of complex data loading operations.

4. DELETE Statement:

  • Purpose: The DELETE statement is used to remove one or more rows from a table.
  • Syntax: DELETE FROM table_name WHERE condition;
  • Use Cases: DELETE is used to remove specific rows from a table based on a specified condition. It can help manage and maintain data within a table.

5. UPDATE Statement:

  • Purpose: The UPDATE statement is used to modify existing data in a table.
  • Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
  • Use Cases: UPDATE is used when you need to change the values of one or more columns in existing rows of a table based on a specified condition.

6. TRUNCATE Statement:

  • Purpose: The TRUNCATE statement is used to remove all rows from a table quickly. It is more efficient than the DELETE statement for removing all data.
  • Syntax: TRUNCATE TABLE table_name;
  • Use Cases: TRUNCATE is typically used when you want to remove all data from a table but keep the table structure intact. It is faster and requires fewer resources than DELETE.

These SQL statements are fundamental for working with data in Oracle databases. They allow you to retrieve, insert, update, and delete data, providing the core functionality for managing and manipulating database tables.