CREATE OR REPLACE FUNCTION APPS.SGDF_NEXT_QUANTITY(V_ORDER_NO IN VARCHAR2,
V_ITEM IN VARCHAR2, V_CURR IN VARCHAR2 , V_PRICE IN NUMBER , V_CUSTOMER_NUMBER IN VARCHAR2)
RETURN NUMBER IS NEXT_QUANTITY NUMBER :=0 ;
BEGIN
SELECT SUM(NVL(L.ORDERED_QUANTITY,0)) INTO NEXT_QUANTITY
FROM ONT.OE_ORDER_LINES_ALL L ,
ONT.OE_ORDER_HEADERS_ALL H,
INV.MTL_SYSTEM_ITEMS_B MSI,
ONT.OE_TRANSACTION_TYPES_TL O,
APPS.RA_CUSTOMERS RC
WHERE H.HEADER_ID = L.HEADER_ID
AND NVL(L.CANCELLED_FLAG,'N')<>'Y'
AND NVL(H.CANCELLED_FLAG,'N')<>'Y'
AND O.TRANSACTION_TYPE_ID IN (2855,2859,2873,2875)
-- AND (O.NAME LIKE 'SGD DG%' OR O.NAME LIKE 'SGD TW%MST%')
AND L.INVENTORY_ITEM_ID = MSI.INVENTORY_ITEM_ID
AND H.ORDER_TYPE_ID = O.TRANSACTION_TYPE_ID
AND MSI.ORGANIZATION_ID = 425
AND H.FLOW_STATUS_CODE<>'CANCELLED'
AND L.FLOW_STATUS_CODE<>'CANCELLED'
AND H.SOLD_TO_ORG_ID = RC.CUSTOMER_ID
AND H.TRANSACTIONAL_CURR_CODE= V_CURR
AND L.UNIT_SELLING_PRICE != V_PRICE
AND MSI.SEGMENT1= V_ITEM
AND RC.CUSTOMER_NUMBER = V_CUSTOMER_NUMBER
AND H.CREATION_DATE IN
(SELECT MIN(H.CREATION_DATE)
FROM ONT.OE_ORDER_LINES_ALL L,
ONT.OE_ORDER_HEADERS_ALL H,
ONT.OE_TRANSACTION_TYPES_TL O,
INV.MTL_SYSTEM_ITEMS_B MSI
WHERE H.HEADER_ID = L.HEADER_ID
AND NVL(L.CANCELLED_FLAG,'N')<>'Y'
AND NVL(H.CANCELLED_FLAG,'N')<>'Y'
AND L.INVENTORY_ITEM_ID = MSI.INVENTORY_ITEM_ID
AND H.ORDER_TYPE_ID = O.TRANSACTION_TYPE_ID
AND MSI.ORGANIZATION_ID = 425
AND H.TRANSACTIONAL_CURR_CODE= V_CURR
AND H.FLOW_STATUS_CODE<>'CANCELLED'
AND L.FLOW_STATUS_CODE<>'CANCELLED'
AND MSI.SEGMENT1= V_ITEM
AND O.TRANSACTION_TYPE_ID IN (2855,2859,2873,2875)
-- AND (O.NAME LIKE 'SGD DG%' OR O.NAME LIKE 'SGD TW%MST%')
AND H.CREATION_DATE >
(SELECT H.CREATION_DATE
FROM ONT.OE_ORDER_LINES_ALL L,
ONT.OE_ORDER_HEADERS_ALL H,
ONT.OE_TRANSACTION_TYPES_TL O,
INV.MTL_SYSTEM_ITEMS_B MSI
WHERE H.HEADER_ID = L.HEADER_ID
AND L.INVENTORY_ITEM_ID =MSI.INVENTORY_ITEM_ID
AND H.ORDER_TYPE_ID = O.TRANSACTION_TYPE_ID
AND MSI.ORGANIZATION_ID = 425
AND O.TRANSACTION_TYPE_ID IN (2855,2859,2873,2875)
-- AND (O.NAME LIKE 'SGD DG%' OR O.NAME LIKE 'SGD TW%MST%')
AND NVL(L.CANCELLED_FLAG,'N')<>'Y'
AND NVL(H.CANCELLED_FLAG,'N')<>'Y'
AND H.FLOW_STATUS_CODE<>'CANCELLED'
AND L.FLOW_STATUS_CODE<>'CANCELLED'
AND H.ORDER_NUMBER= V_ORDER_NO
AND H.TRANSACTIONAL_CURR_CODE= V_CURR
AND MSI.SEGMENT1= V_ITEM
AND ROWNUM < 2 ) )
-- AND ROWNUM < 2
;
RETURN(NEXT_QUANTITY);
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN '0';
END ;
/*
SELECT ORDER_NUMBER,CUSTOMER_NUMBER,ORDERED_ITEM,UNIT_SELLING_PRICE,SGDF_NEXT_QUANTITY(ORDER_NUMBER,ORDERED_ITEM,TRANSACTIONAL_CURR_CODE,UNIT_SELLING_PRICE, CUSTOMER_NUMBER)
FROM (
SELECT DISTINCT H.ORDER_NUMBER,RC.CUSTOMER_NUMBER , H.CREATION_DATE,H.TRANSACTIONAL_CURR_CODE,L.ORDERED_ITEM,L.UNIT_SELLING_PRICE ,L.FLOW_STATUS_CODE
FROM ONT.OE_ORDER_HEADERS_ALL H, ONT.OE_ORDER_LINES_ALL L ,APPS.RA_CUSTOMERS RC
WHERE H.HEADER_ID=L.HEADER_ID AND H.SOLD_TO_ORG_ID = RC.CUSTOMER_ID AND L.FLOW_STATUS_CODE<>'CANCELLED'
) WHERE ORDER_NUMBER LIKE '6010011__' ;
*/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/729024/viewspace-669996/,如需转载,请注明出处,否则将追究法律责任。