Hello All,
Please help us to write a query to update only specific rows from the table. Requirement is to update old Employee ID with the new Employee ID, but getting "Unique Constraint" Error as certain tables already contain old and New employee IDs. We should ignore those rows and update remaining.
Create a mapping table with old and new employee ID's
SQL> CREATE TABLE PS_EMP_MAPP_TBL (OLD_EMPLID VARCHAR2(11) NOT NULL,
2 NEW_EMPLID VARCHAR2(11) NOT NULL );
Table created
Insert rows into Mapping table.
SQL> INSERT INTO PS_EMP_MAPP_TBL VALUES ('O12345', 'N12345');
1 row created.
SQL> INSERT INTO PS_EMP_MAPP_TBL VALUES ('O56785', 'N56785');
1 row created.
SQL> INSERT INTO PS_EMP_MAPP_TBL VALUES ('O67321', 'N67321');
1 row created.
SQL>
Create transaction table. One Employee has both old and New Employee IDs in this table and other two employees have only OLD employee IDs. EMPLID is key field
SQL> CREATE TABLE PS_TEST56_TBL (EMPLID VARCHAR2(11) NOT NULL PRIMARY KEY,
EMP_NAME VARCHAR2(30) NOT NULL
);
Table Created
Insert rows into the transaction table.
SQL> INSERT INTO SYSADM.PS_TEST56_TBL VALUES ('N12345','TEST1');
1 row created.
SQL> INSERT INTO SYSADM.PS_TEST56_TBL VALUES ('O12345','TEST1');
1 row created.
SQL> INSERT INTO SYSADM.PS_TEST56_TBL VALUES ('O56785','TEST2');
1 row created.
SQL> INSERT INTO SYSADM.PS_TEST56_TBL VALUES ('O67321','TEST3');
1 row created.
Requirement is to update only two rows from Transaction table, without getting Unique constaint error for New employee ID "N12345" (for old Employee ID "O12345").
Thank You !