I try to run the following code but receive "single-row subquery returns more than one row" error. Any idea why it happened and how can i fix this?
DECLARE
CURSOR
CUR IS
SELECT
T.bom_header,
T.sap_cage_cd,
I
.part_doc_nbr,
I
.cage_cd,
P.ec_revision_mfg,
(SELECT NVL (I2.sap_xref_no, I2.part_doc_nbr)
FROM eissap.tbitem i
WHERE I.item IN (SELECT comp_part
FROM eissap.tbpart_config_comp_config
WHERE item = comp_part)) AS sap_xref_no
,
C
.comp_config,
C
.qty_per_mfg,
C
.unit_of_measure_cd,
I
.item
FROM TEMP_SAP_BOMS_LIST_BKP T,
EISSAP
.TBITEM I,
EISSAP
.TBPART_CONFIG_COMP_CONFIG C,
EISSAP
.TBPART P,
EISSAP
.TBITEM I2
WHERE (T.bom_header = I.part_doc_nbr OR T.bom_header = I.sap_xref_no)
AND T.sap_cage_cd = I.cage_cd
AND I.item = C.PART_ITEM
AND I2.ITEM = C.COMP_PART
AND I.item = P.item
AND c.config = (SELECT MAX (c1.config)
FROM EISSAP.tbpart_config_comp_config c1
WHERE c1.part_item = C.part_item);
BEGIN
FOR
C4 IN CUR LOOP
INSERT
INTO TEMP_SAP_BOMS
(
bom_header
,
sap_cage_cd
,
part_doc_nbr
,
cage_cd
,
ec_revision_mfg
,
sap_xref_no
,
comp_config
,
qty_per_mfg
,
unit_of_measure_cd
,
item
)
VALUES(
C4.bom_header,
C4
.sap_cage_cd,
C4
.part_doc_nbr,
C4
.cage_cd,
C4
.ec_revision_mfg,
C4
.sap_xref_no,
C4
.comp_config,
C4
.qty_per_mfg,
C4
.unit_of_measure_cd,
C4
.item);
CLOSE
CUR;
END
LOOP;
END;