본문 바로가기
프로그래밍/Oracle

[PL/SQL] sample code(CURSOR)

by Daily Investing 2013. 7. 10.
반응형

DECLARE
    N_INS_Q_SUM         NUMBER(13);
    N_013_MENGE         NUMBER(13);
    CURSOR CR_MM017 IS
      SELECT 
        MM017.MANDT
        , MM017.INVNR
        , MM017.INVITEM
        , MM017.EBELN
        , MM017.EBELP
    FROM    TABLE001 MM017
    WHERE   1=1
    AND     MM017.MANDT = #G_MANDT#
    AND     MM017.INVNR = #INVNR#
    AND     MM017.LIFNR = #LIFNR#
   

BEGIN
    FOR I_ROW IN CR_MM017 LOOP
        SELECT  MENGE
        INTO    N_013_MENGE
        FROM    TABLE002
        WHERE   MANDT = #G_MANDT#
        AND     EBELN = I_ROW.EBELN
        AND     EBELP = I_ROW.EBELP;
       
        SELECT  SUM(INS_Q) AS INS_Q
        INTO    N_INS_Q_SUM        
        FROM    TABLE001
        WHERE   MANDT = #G_MANDT#
        AND     EBELN = I_ROW.EBELN
        AND     EBELP = I_ROW.EBELP;

        IF  N_013_MENGE = N_INS_Q_SUM THEN
            UPDATE  TABLE002
            SET     PO_STATE_BEF = (SELECT PO_STATE FROM ZMMT013 WHERE MANDT = #G_MANDT# AND EBELN = I_ROW.EBELN AND EBELP = I_ROW.EBELP)
                    , PO_STATE = '91'
            WHERE   MANDT = #G_MANDT#
            AND     EBELN = I_ROW.EBELN
            AND     EBELP = I_ROW.EBELP;
        END IF;
    END LOOP;   
END;       

 

 

반응형