While creating a SQL query to extract Purchase Order information, the subquery to retrieve item number afiliated with the Purchase order returns the following error: ORA-01427: single-row subquery returns more than one row.
Below is the full SQL query:
SELECT
distinct item.item_number item_number
FROM
po_headers_all pha
,fun_all_business_units_v fav
,po_buyers_val_v pbv_inner
,poz_suppliers_v psv
,po_lines_all pla
,egp_categories_vl egp
,hr_locations_all hla
,hr_locations_all hla2
,po_distributions_all pda
,po_line_locations_all plla
,gl_code_combinations gcc
,pjf_tasks_v pt
,poz_supplier_sites_all_m pss
,hr_organization_units hru
,(select pjf.name,pb.segment1,pb.project_id
from pjf_projects_all_b pb, pjf_projects_all_tl pjf
where pjf.project_id = pb.project_id)
project
,(select pha2.segment1 ,pla2.line_num, pla2.po_line_id,pha2.po_header_id
from po_headers_all pha2 ,po_lines_all pla2
where pha2.po_header_id = pla2.po_header_id
and pha2.type_lookup_code(+) = 'BLANKET')
agreement
,(select esiav.item_number,esiav.inventory_item_id
FROM egp_system_items_b esiav,inv_org_parameters IOP
WHERE ESIAV.organization_id = IOP.organization_id
AND IOP.organization_code='WSH_ITEMMSTR')
item
/* Old logic- requisition number not getting populated
,(select
prh.requisition_number
,prl.po_header_id
,prl.req_bu_id
,prl.po_line_id
,pf.full_name
from
por_requisition_lines_all prl
,por_requisition_headers_all prh
,PER_PERSON_NAMES_F pf
where
prl.requisition_header_id = prh.requisition_header_id
AND prl.requester_id= pf.person_id(+)
AND pf.name_type='GLOBAL')
rq */
WHERE 1=1
and pha.po_header_id = pla.po_header_id
and pha.po_header_id = pda.po_header_id (+)
and pha.agent_id = pbv_inner.person_id
and pha.vendor_id = psv.vendor_id
and plla.ship_to_location_id = hla.location_id(+)
and pha.req_bu_id = fav.bu_id(+)
and pha.vendor_site_id = pss.vendor_site_id
and pla.po_line_id = pda.po_line_id(+)
and pla.item_id = item.inventory_item_id(+)
and pla.category_id = egp.category_id
and pla.po_line_id = plla.po_line_id
and pla.from_header_id = agreement.po_header_id(+)
and pla.from_line_id = agreement.po_line_id(+)
and pda.deliver_to_location_id = hla2.location_id(+)
and pda.code_combination_id = gcc.code_combination_id(+)
and pda.pjc_organization_id = hru.organization_id(+)
and pda.pjc_project_id = project.project_id(+)
and pda.pjc_task_id = pt.task_id(+)
and pss.vendor_id = psv.vendor_id
/* Old logic- requisition number not getting populated
and pha.po_header_id = rq.po_header_id(+)
and pla.req_bu_id = rq.req_bu_id(+)
and pla.po_line_id = rq.po_line_id(+) */
and pha.type_lookup_code = 'STANDARD'
and pha.document_status not in ('INCOMPLETE','CANCELED','REJECTED')
and pla.line_status not in ('INCOMPLETE','CANCELLED')
I expect the ability to retrieve all items numbers afiliated with the purchase order, with minimal changes.