Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle copy data to another table

Tags:

sql

oracle

In the Oracle, I copy data from a backup to a new table, it doesn't work.

what is the correct syntax ?

Thanks

select CODE, MESSAGE into EXCEPTION_CODES (CODE, MESSAGE) from Exception_code_tmp 

the error is

**SQL Error: ORA-00905: missing keyword 00905. 00000 -  "missing keyword"** 
like image 265
user595234 Avatar asked Jul 13 '12 14:07

user595234


2 Answers

You need an INSERT ... SELECT

INSERT INTO exception_codes( code, message )   SELECT code, message     FROM exception_code_tmp 
like image 154
Justin Cave Avatar answered Sep 20 '22 19:09

Justin Cave


If you want to create table with data . First create the table :

create table new_table as ( select * from old_table);  

and then insert

insert into new_table ( select * from old_table); 

If you want to create table without data . You can use :

create table new_table as ( select * from old_table where 1=0); 
like image 40
Trideep Rath Avatar answered Sep 19 '22 19:09

Trideep Rath