Insert - (Oracle Query)
The INSERT
statement in Oracle is used to add new records to a table. It is a Data Manipulation Language (DML) statement that allows you to insert data into a table.
Syntax
The basic syntax for the INSERT
statement in Oracle is as follows:
INSERT INTO table_name (column1, column2, ..., columnN)
VALUES (value1, value2, ..., valueN);
Here, table_name
is the name of the table into which you wish to insert data. You then specify the names of the columns in the table where you wish to insert data. This is followed by the VALUES
keyword, and the data that you wish to insert.
If you wish to insert data into all columns of the table, you can use the following syntax:
INSERT INTO table_name
VALUES (value1, value2, ..., valueN);
Example
Let's say we have a table called employees
:
emp_id | first_name | last_name | salary | hire_date |
---|---|---|---|---|
1 | John | Smith | 50000 | 01-JAN-2020 |
2 | Jane | Doe | 60000 | 01-FEB-2020 |
To insert a new record into this table, we can use the following INSERT
statement:
INSERT INTO employees (emp_id, first_name, last_name, salary, hire_date)
VALUES (3, 'Mike', 'Johnson', 70000, '01-MAR-2020');
This will insert a new record into the table with the following values:
emp_id | first_name | last_name | salary | hire_date |
---|---|---|---|---|
1 | John | Smith | 50000 | 01-JAN-2020 |
2 | Jane | Doe | 60000 | 01-FEB-2020 |
3 | Mike | Johnson | 70000 | 01-MAR-2020 |
Output
The output of an INSERT
statement is the number of rows affected by the statement. When inserting a single record, the output will be 1
.
Explanation
In the above example, we used the INSERT
statement to add a new record to the employees
table. We specified the column names where we wanted to insert data, followed by the values that we wanted to insert. The result was a new record in the table with the specified values.
Use
The INSERT
statement in Oracle is used to add new records to a table. This is useful when you want to add new data to a table, such as when a new employee is hired or a new product is added to a database.
Important Points
- The
INSERT
statement in Oracle is used to add new records to a table. - You can specify the columns and values where you wish to insert data.
- If you want to insert data into all columns of the table, you can omit the column names from the statement.
- The output of an
INSERT
statement is the number of rows affected by the statement.
Summary
In summary, the INSERT
statement in Oracle is a DML statement that allows you to insert data into a table. You can specify the columns and values where you wish to insert data, or you can specify all columns of the table. The output of the statement is the number of rows affected by the statement.