CREATE TABLE TEST4
(
ITEM VARCHAR2 (12),
JOBNUM VARCHAR2 (12),
GENERIC VARCHAR2 (20),
TERM_EQUIP_GROUP_ID VARCHAR2 (20),
PRIMARY KEY (ITEM, JOBNUM)
);
INSERT INTO TEST4 VALUES ('AAAA1', 'XXXX1', '1AE12.05', '1AE');
INSERT INTO TEST4 VALUES ('AAAA1', 'XXXX2', '1AE12.06', '1AE');
INSERT INTO TEST4 VALUES ('AAAA1', 'XXXX3', '1AE12.07', '1AE');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY1', '5E8', '5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY2', '5E9', '5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY3', '5E10','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY4', '5E11','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY5', '5E12','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY6', '5E13','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY7', '5E14','5ES');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ1', 'REL-18', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ2', 'REL-20', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ3', 'REL-21', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ4', 'REL-22', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ5', 'REL-23', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ6', 'REL-24', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ7', 'REL-25', 'DCO');
--- This update statement return ORA-01427: single-row subquery
--- returns more than one row. When i am trying to update
--- TEST4.generic based on below case statement.
--- Never used self join with update & case?
UPDATE TEST4
SET GENERIC =
(SELECT CASE WHEN A.GENERIC='1AE12.05' AND A.TERM_EQUIP_GROUP_ID ='1AE' THEN 'UNSPEC'
WHEN A.GENERIC='1AE12.06' AND A.TERM_EQUIP_GROUP_ID ='1AE' THEN 'UNSPEC'
WHEN A.GENERIC='1AE12.07' AND A.TERM_EQUIP_GROUP_ID ='1AE' THEN 'UNSPEC'
WHEN A.GENERIC='5E8' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN 'UNSPEC'
WHEN A.GENERIC='5E9' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN 'UNSPEC'
WHEN A.GENERIC='5E10' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN 'UNSPEC'
WHEN A.GENERIC='5E11' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E11'
WHEN A.GENERIC='5E12' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E12'
WHEN A.GENERIC='5E13' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E13'
WHEN A.GENERIC='5E14' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E14'
WHEN A.GENERIC='REL-18' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'UNSPEC'
WHEN A.GENERIC='REL-20' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R20'
WHEN A.GENERIC='REL-21' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R21'
WHEN A.GENERIC='REL-22' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R22'
WHEN A.GENERIC='REL-23' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R23'
WHEN A.GENERIC='REL-24' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R24'
WHEN A.GENERIC='REL-25' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R25'
ELSE NULL
END
FROM TEST4 A, TEST4 B
WHERE A.CLLI=B.CLLI AND A.JOB_ID=B.JOB_ID AND A.TERM_EQUIP_GROUP_ID = B.TERM_EQUIP_GROUP_ID)
(
ITEM VARCHAR2 (12),
JOBNUM VARCHAR2 (12),
GENERIC VARCHAR2 (20),
TERM_EQUIP_GROUP_ID VARCHAR2 (20),
PRIMARY KEY (ITEM, JOBNUM)
);
INSERT INTO TEST4 VALUES ('AAAA1', 'XXXX1', '1AE12.05', '1AE');
INSERT INTO TEST4 VALUES ('AAAA1', 'XXXX2', '1AE12.06', '1AE');
INSERT INTO TEST4 VALUES ('AAAA1', 'XXXX3', '1AE12.07', '1AE');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY1', '5E8', '5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY2', '5E9', '5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY3', '5E10','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY4', '5E11','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY5', '5E12','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY6', '5E13','5ES');
INSERT INTO TEST4 VALUES ('BBBB1', 'YYYY7', '5E14','5ES');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ1', 'REL-18', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ2', 'REL-20', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ3', 'REL-21', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ4', 'REL-22', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ5', 'REL-23', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ6', 'REL-24', 'DCO');
INSERT INTO TEST4 VALUES ('CCCC1', 'ZZZZ7', 'REL-25', 'DCO');
--- This update statement return ORA-01427: single-row subquery
--- returns more than one row. When i am trying to update
--- TEST4.generic based on below case statement.
--- Never used self join with update & case?
UPDATE TEST4
SET GENERIC =
(SELECT CASE WHEN A.GENERIC='1AE12.05' AND A.TERM_EQUIP_GROUP_ID ='1AE' THEN 'UNSPEC'
WHEN A.GENERIC='1AE12.06' AND A.TERM_EQUIP_GROUP_ID ='1AE' THEN 'UNSPEC'
WHEN A.GENERIC='1AE12.07' AND A.TERM_EQUIP_GROUP_ID ='1AE' THEN 'UNSPEC'
WHEN A.GENERIC='5E8' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN 'UNSPEC'
WHEN A.GENERIC='5E9' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN 'UNSPEC'
WHEN A.GENERIC='5E10' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN 'UNSPEC'
WHEN A.GENERIC='5E11' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E11'
WHEN A.GENERIC='5E12' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E12'
WHEN A.GENERIC='5E13' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E13'
WHEN A.GENERIC='5E14' AND A.TERM_EQUIP_GROUP_ID ='5ES' THEN '5E14'
WHEN A.GENERIC='REL-18' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'UNSPEC'
WHEN A.GENERIC='REL-20' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R20'
WHEN A.GENERIC='REL-21' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R21'
WHEN A.GENERIC='REL-22' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R22'
WHEN A.GENERIC='REL-23' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R23'
WHEN A.GENERIC='REL-24' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R24'
WHEN A.GENERIC='REL-25' AND A.TERM_EQUIP_GROUP_ID ='DCO' THEN 'R25'
ELSE NULL
END
FROM TEST4 A, TEST4 B
WHERE A.CLLI=B.CLLI AND A.JOB_ID=B.JOB_ID AND A.TERM_EQUIP_GROUP_ID = B.TERM_EQUIP_GROUP_ID)