Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Auto sequence + insert from another table

842487Mar 8 2011 — edited Mar 8 2011
Hi All,
I am using ORACLE 10g release2 running on windows server2003.

I have 2 tables named EMP_HOME and EMP_WORK. In the table EMP_WORK the primary key column is EMP_ID and it is also an autoincrementing column.

Now I need to insert some data to the EMP_WORK table from EMP_HOME. EMP_HOME has PERSON_ID as its primary key.

Following are the columns of the 2 table:

SQL> DESC EMP_HOME;
Name Null? Type
----------------------------------------------------- -------- ------------
PERSON_ID NOT NULL NUMBER(38)
FIRST_NAME NOT NULL VARCHAR2(30)
LAST_NAME VARCHAR2(20)
ADDRESS VARCHAR2(30)
CITY VARCHAR2(15)

SQL> DESC EMP_WORK;
Name Null? Type
----------------------------------------------------- -------- ------------
EMP_ID NOT NULL NUMBER(38) >>This column is an autoincrement or sequence with "increment by 1".
FIRST_NAME VARCHAR2(20)
LAST_NAME VARCHAR2(20)
DEPT VARCHAR2(10)
PERSON_ID NUMBER(38) >>This column is a foreign key referencing EMP_HOME(PERSON_ID).


Now I need to insert into EMP_WORK(EMP_ID,FIRST_NAME,LAST_NAME,P_ID) FROM EMP_HOME.
Now here comes the prob. I need to take the values into EMP_ID column as nextval and the others from the EMP_HOME table.

Please help me by providing the right command which will do the job.

Thanks in advance.
This post has been answered by Peter Gjelstrup on Mar 8 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2011
Added on Mar 8 2011
2 comments
993 views