📜  SELECT INTO Oracle - SQL (1)

📅  最后修改于: 2023-12-03 15:20:03.660000             🧑  作者: Mango

SELECT INTO Oracle - SQL

SELECT INTO is used to create a new table in Oracle SQL by selecting data from an existing table. The new table will have the same structure as the existing table, and can contain all or some of the columns from the existing table.

Syntax

The basic syntax for the SELECT INTO statement in Oracle SQL is:

SELECT column1, column2, ...
INTO new_table
FROM existing_table
WHERE condition;
Example

Let's say we have a table called employees with columns such as employee_id, first_name, last_name, department_id, and hire_date. We want to create a new table called new_employees that contains only the employee_id, first_name, and last_name columns from the employees table.

The SQL statement to create the new_employees table is:

SELECT employee_id, first_name, last_name
INTO new_employees
FROM employees;

This will create a new table called new_employees with the same columns and data types as the employees table, and will contain only the employee_id, first_name, and last_name columns.

Conclusion

SELECT INTO is a powerful feature in Oracle SQL that allows you to create new tables based on the data from existing tables. By selecting only the columns you need, you can create more efficient and streamlined tables that are easier to work with in your SQL queries.