Home » SQL & PL/SQL » SQL & PL/SQL » how to insert data from one table to another table
how to insert data from one table to another table [message #292026] Mon, 07 January 2008 08:43 Go to next message
karunakar_adepu84
Messages: 43
Registered: January 2008
Member



If we I table emp with column names ename,sal,deptno
in this table I have the data with 5 records.
I want to transfer this same data into another table called
as emp_info with column empno,ename,sal,deptno
but on empno I want to use sequence to insert for empnumbers
is there any sql query plz suggest me..........

Re: how to insert data from one table to another table [message #292028 is a reply to message #292026] Mon, 07 January 2008 08:44 Go to previous messageGo to next message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Create a sequence.
Use "create table as select" statement
In this statement use "nextval" on your sequence to get the new empnumbers.

Regards
Michel
Re: how to insert data from one table to another table [message #292029 is a reply to message #292026] Mon, 07 January 2008 08:46 Go to previous message
pablolee
Messages: 2836
Registered: May 2007
Location: Scotland
Senior Member
Rather than using a sequence, you could use rownum:

air code
insert into tabletarget (id, name, sal)
select rownum, name, sale
from tablesource

Or something of a similar ilk.
Although as Michel proffers the solution as per your request ... Smile

[Updated on: Mon, 07 January 2008 08:47]

Report message to a moderator

Previous Topic: CREATE TABLE throws ORA-00972 Identifier is too long
Next Topic: how to reject trailing spaces?
Goto Forum:
  


Current Time: Sat Dec 10 02:54:05 CST 2016

Total time taken to generate the page: 0.23876 seconds