Auto sequence + insert from another table
842487Mar 8 2011 — edited Mar 8 2011Hi 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.