How to use INSERT Statement In SQL
INSERT statement in the PL/SQL is used to add the new records or rows of data into the table. It allows u to specify the table name, columns where the data will be inserted and the corresponding values to be inserted into the columns.
Syntax for INSERT Statement:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
Explanation:
- table_name is the name of the table, which we want to insert the data.
- (column1, column2, ….) are optional lists of the columns in table. If specified, you need to be provide the values for those columns in the same order.
- VALUES (value1, value2, …) are values to be inserted into specified columns. These values must match the data types of the provided columns.
Examples of INSERT Statement
Example 1:
Let’ insert some data into the students table.
INSERT INTO students (student_id, first_name, last_name)
VALUES (1, 'John', 'Doe');
INSERT INTO students (student_id, first_name, last_name)
VALUES (2, 'Jane', 'Smith');
Output:
student_id |
first_name |
last_name |
---|---|---|
1 |
John |
Doe |
2 |
Jane |
Smith |
Explanation:
- Each INSERT statement inserts one row of the data into the students table.
- The syntax of the row inserted the same as before, specifying the columns to insert the data into and it provides the corresponding values into the table.
Example 2:
INSERT INTO students (student_id, first_name, last_name)
VALUES (3, 'Michael', 'Johnson');
INSERT INTO students (student_id, first_name, last_name)
VALUES (4, 'Emily', 'Williams');
Output:
student_id |
first_name |
last_name |
---|---|---|
1 |
John |
Doe |
2 |
Jane |
Smith |
3 |
Michael |
Johnson |
4 |
Emily |
Williams |
Explanation:
- Each INSERT statement inserts one row of the data into the students table.
- The syntax of the row inserted the same as before, specifying the columns to insert the data into and it provides the corresponding values into the table.
How to Use PL SQL Insert, Update, Delete And Select Statement?
PL/SQL is a powerful extension of SQL specifically designed for Oracle databases. It enables developers to create procedural logic and execute SQL commands within Oracle database environments. In this article, we will explore the usage of fundamental PL/SQL statements such as INSERT, UPDATE, DELETE and SELECT with he help of various examples which are essential for manipulating data in Oracle databases.