请大家帮忙分析一个函数
FUNCTION GET_LOC(
P_ITEM IN VARCHAR2
) RETURN VARCHAR IS
V_RETURN VARCHAR2(30);
BEGIN ----BEGIN1
--------------------------------SELECT1
SELECT '库存-'||C.SEGMENT1
INTO V_RETURN
FROM INV.MTL_ONHAND_QUANTITIES A,
INV.MTL_SYSTEM_ITEMS B,
INV.MTL_ITEM_LOCATIONS C
WHERE A.ORGANIZATION_ID=B.ORGANIZATION_ID
AND A.INVENTORY_ITEM_ID=B.INVENTORY_ITEM_ID
AND C.ORGANIZATION_ID=4
AND C.SUBINVENTORY_CODE=A.SUBINVENTORY_CODE
AND A.LOCATOR_ID=C.INVENTORY_LOCATION_ID
AND A.SUBINVENTORY_CODE='C010整机'
AND B.ORGANIZATION_ID=4
AND B.SEGMENT1 =P_ITEM ;
RETURN(V_RETURN);
EXCEPTION WHEN OTHERS THEN ----SELECT1没有返回值时,才由SELECT2给返回值
BEGIN ----BEGIN2
--------------------------------SELECT2
SELECT /*MMT.TRANSACTION_ID,
MMT.SUBINVENTORY_CODE,
MMT.TRANSACTION_TYPE_ID,
MMT.TRANSACTION_ACTION_ID,
MTT.TRANSACTION_TYPE_NAME,
MMT.TRANSACTION_QUANTITY,
MMT.TRANSACTION_REFERENCE,
MMT.TRANSACTION_DATE ,*/
'T在制-'||MIL.SEGMENT1
INTO V_RETURN
FROM INV.MTL_MATERIAL_TRANSACTIONS MMT,
INV.MTL_ITEM_LOCATIONS MIL,
INV.MTL_TRANSACTION_TYPES MTT
WHERE MMT.ORGANIZATION_ID=MIL.ORGANIZATION_ID(+)
AND MMT.LOCATOR_ID=MIL.INVENTORY_LOCATION_ID(+)
AND MMT.TRANSACTION_TYPE_ID=MTT.TRANSACTION_TYPE_ID
AND MMT.TRANSACTION_ID=(SELECT MAX(MMT2.TRANSACTION_ID)
FROM INV.MTL_MATERIAL_TRANSACTIONS MMT2,
INV.MTL_SYSTEM_ITEMS MSI2
WHERE MSI2.ORGANIZATION_ID=MMT2.ORGANIZATION_ID
&nb