SELECT gbh.batch_no
FROM gme_batch_header gbh
WHERE EXISTS
(SELECT 1
FROM mtl_transaction_lot_numbers mtln,mtl_lot_numbers lot,
mtl_material_transactions mmt
WHERE mmt.transaction_type_id = 35 --- WIP Issue
AND mtln.lot_number = lot.lot_number
AND mtln.transaction_id = mmt.transaction_id
AND mmt.organization_id = NVL(:p_organization_id,mmt.organization_id)
AND lot.lot_number = NVL(:P_lot_number,lot.lot_number)
AND mmt.transaction_source_id is not null
AND gbh.batch_id = mmt.transaction_source_id)
/