SELECT INTO using Oracle SELECT INTO using Oracle oracle oracle

SELECT INTO using Oracle


If NEW_TABLE already exists then ...

insert into new_table select * from old_table/

If you want to create NEW_TABLE based on the records in OLD_TABLE ...

create table new_table as select * from old_table/

If the purpose is to create a new but empty table then use a WHERE clause with a condition which can never be true:

create table new_table as select * from old_tablewhere 1 = 2/

Remember that CREATE TABLE ... AS SELECT creates only a table with the same projection as the source table. The new table does not have any constraints, triggers or indexes which the original table might have. Those still have to be added manually (if they are required).


select into is used in pl/sql to set a variable to field values. Instead, use

create table new_table as select * from old_table


Use:

create table new_table_name asselect column_name,[more columns] from Existed_table;

Example:

create table deptasselect empno, ename from emp;

If the table already exists:

insert into new_tablename select columns_list from Existed_table;