CREATE TABLE T_DEPARTMENT (
DEPARTMENT_ID NUMBER PRIMARY KEY NOT NULL,
DEPARTMENT_NAME VARCHAR2(50) NOT NULL);
INSERT INTO T_DEPARTMENT (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES( 1, 'ACCOUNTS' );
INSERT INTO T_DEPARTMENT (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES( 2, 'CALL CENTER' );
INSERT INTO T_DEPARTMENT (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES( 3, 'PURCHASE' );
INSERT INTO T_DEPARTMENT (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES( 4, 'MARKETING' );
INSERT INTO T_DEPARTMENT (DEPARTMENT_ID, DEPARTMENT_NAME) VALUES( 5, 'SALES' );
SQL> SELECT * FROM T_DEPARTMENT ORDER BY 1;
DEPARTMENT_ID DEPARTMENT_NAME
------------- --------------------------------------------------
1 ACCOUNTS
2 CALL CENTER
3 PURCHASE
4 MARKETING
5 SALES
UPDATE T_DEPARTMENT SET DEPARTMENT_ID = 4 WHERE DEPARTMENT_NAME = 'PURCHASE';
UPDATE T_DEPARTMENT SET DEPARTMENT_ID = 3 WHERE DEPARTMENT_NAME = 'MARKETING';
The above set of DMLs will not work as it violates the unique key constraint. Try the following DML
UPDATE T_DEPARTMENT SET DEPARTMENT_ID = DECODE(DEPARTMENT_NAME,
'MARKETING', 3,
'PURCHASE', 4 )
WHERE DEPARTMENT_NAME IN ( 'PURCHASE', 'MARKETING' );
SQL> SELECT * FROM T_DEPARTMENT ORDER BY 1;
DEPARTMENT_ID DEPARTMENT_NAME
------------- --------------------------------------------------
1 ACCOUNTS
2 CALL CENTER
3 MARKETING
4 PURCHASE
5 SALES