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 ISSELECT
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 LOOPINSERT
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;
Jignesh TrivediPosted Mar 16, 2015, 11:47 PM
Hi,
I think, sub query within select stament may return more than one value, use top(1) or rownum = 1 (in where condition) to select only one row
like
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) and rownum =1
hope this will help you.
Muhammad AlviPosted Mar 17, 2015, 7:43 AM
Vikram AgrawalPosted Mar 16, 2015, 8:56 AM
Well
remove this block of code and put it like this
NVL (I2.sap_xref_no, I2.part_doc_nbr) AS sap_xref_no
and make where clause as follow
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 I.item IN (SELECT comp_part FROM eissap.tbpart_config_comp_config
WHERE item = comp_part)
AND c.config = (SELECT MAX (c1.config)
FROM EISSAP.tbpart_config_comp_config c1
WHERE c1.part_item = C.part_item);
thanks
Muhammad AlviPosted Mar 16, 2015, 8:44 AM
Vikram AgrawalPosted Mar 16, 2015, 8:33 AM
Hi Muhammad Alvi,
I think in your script error in this block
(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
try with replace this part of code with following code
(SELECT NVL (itm.sap_xref_no, itm.part_doc_nbr)
FROM eissap.tbitem itm
WHERE Itm.item IN (SELECT comp_part
FROM eissap.tbpart_config_comp_config
WHERE item = comp_part)) AS sap_xref_no
Thanks,
Hope this will helpful to you
Muhammad AlviPosted Mar 16, 2015, 8:18 AM
Khargesh RajputPosted Mar 13, 2015, 12:26 AM
your query
(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))
will return more then one records