tags:

views:

261

answers:

2

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?

Thanks!


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

http://www.w3schools.com/Sql/sql_select_into.asp

+2  A: 

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
wallyk
I though SELECT INTO was part of the Standard. Did Oracle do something strange here or was it never part of the standard?
Robert Gould
`select into` is part of pl/sql. It is a language for writing stored procedures and has no direct relation to sql standard. And yes, Oracle made many things that were never part of the standard =)
Rorick
+6  A: 

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
/
APC
Thanks! at least now I know that I wasn't going mad :)
Robert Gould
The second DDL statement should read: create table new_table as select * from old_table
PenFold
@PenFold - good catch. Thanks for that.
APC
+1 @Robert: Plus, if you just want to copy the schema of old_table, use a negative where clause, like for instance: create new_table as select * from old_table WHERE 1=2.
KMan