SELECT INTO using Oracle

空扰寡人 提交于 2019-11-26 04:07:08

问题


I\'m trying to do a SELECT INTO using Oracle. My query is:

SELECT * INTO new_table FROM old_table;

But I get the following error:

SQL Error: ORA-00905: missing keyword
00905. 00000 -  \"missing keyword\"

Any ideas what\'s wrong?


The Standard behavior of the above should be as I originally thought: However Oracle implemented it totally differently in their own dialect of SQL Oracle Docs on Insert ... Select


回答1:


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
/



回答2:


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



回答3:


Use:

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

Example:

create table dept
as
select empno, ename from emp;

If the table already exists:

insert into new_tablename select columns_list from Existed_table;


来源:https://stackoverflow.com/questions/2250196/select-into-using-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!