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

select number 더하기(+)

by Daily Investing 2013. 8. 1.
반응형

DECLARE
    N_CNT         NUMBER(1);


BEGIN   
    SELECT 
            COUNT(1) AS N_CNT
    INTO    N_CNT
    FROM    ZMMT016
    WHERE   1=1
    AND     MANDT = #G_MANDT#
    AND     CPUDT = TO_CHAR(SYSDATE, 'YYYYMMDD')
    AND     BUDAT = #BUDAT#
    AND     LIFNR = #LIFNR#
    AND     WERKS = #WERKS#
    AND     MATNR = #MATNR#
    AND     BWART = '101'
    AND     WAERS = #WAERS#;
   
   
    IF #INS_Q# > 0 THEN -- 합격수량이 0 보다 클경우만 INSERT 또는 UPDATE 한다.
        IF N_CNT = 0 THEN
            INSERT INTO ZMMT016 (MANDT, CPUDT, BUDAT, LIFNR, WERKS, MATNR, BWART, WAERS, MAKTX, MENGE, MEINS, DMBTR, EXTWG, EWBEZ, EXEDT, EXETM, EXEID, NETPR)
            VALUES(#G_MANDT#, TO_CHAR(SYSDATE, 'YYYYMMDD'), #BUDAT#, #LIFNR#, #WERKS#
                                        , #MATNR#, '101', #WAERS#, #MAKTX#
                                        , CASE #POTYPE# WHEN 'X' THEN TO_NUMBER(#ARV_QTY#) ELSE TO_NUMBER(#IN_CFM_QTY#) END --BOX자재면 ARV_QTY, 개별자재면 UI 에서 입력받은 IN_CFM_QTY
                                        , #MEINS#
                                        , CASE #POTYPE# WHEN 'X' THEN TO_NUMBER(#ARV_QTY#) ELSE TO_NUMBER(#IN_CFM_QTY#) END * TO_NUMBER(#NETPR#)
                                        , #EXTWG#, #EWBEZ#, TO_CHAR(SYSDATE, 'YYYYMMDD'), TO_CHAR(SYSDATE, 'HH24MISS'), '', #NETPR#);  
           
        ELSIF N_CNT = 1 THEN
            UPDATE  ZMMT016
            SET    
                    MENGE = (SELECT  TO_NUMBER(NVL(MENGE,0)) + (CASE #POTYPE# WHEN 'X' THEN TO_NUMBER(NVL(#ARV_QTY#,0)) ELSE TO_NUMBER(NVL(#IN_CFM_QTY#,0)) END)
                            FROM    ZMMT016
                            WHERE   1=1
                            AND     MANDT = #G_MANDT#
                            AND     CPUDT = TO_CHAR(SYSDATE, 'YYYYMMDD')
                            AND     BUDAT = #BUDAT#
                            AND     LIFNR = #LIFNR#
                            AND     WERKS = #WERKS#
                            AND     MATNR = #MATNR#
                            AND     BWART = '101'
                            AND     WAERS = #WAERS#)
                    , DMBTR = (SELECT  TO_NUMBER(NVL(DMBTR,0)) + ((CASE #POTYPE# WHEN 'X' THEN TO_NUMBER(NVL(#ARV_QTY#,0)) ELSE TO_NUMBER(NVL(#IN_CFM_QTY#,0)) END) * TO_NUMBER(#NETPR#))
                              FROM    ZMMT016
                              WHERE   1=1
                              AND     MANDT = #G_MANDT#
                              AND     CPUDT = TO_CHAR(SYSDATE, 'YYYYMMDD')
                              AND     BUDAT = #BUDAT#
                              AND     LIFNR = #LIFNR#
                              AND     WERKS = #WERKS#
                              AND     MATNR = #MATNR#
                              AND     BWART = '101'
                              AND     WAERS = #WAERS#)
                    , EXEDT = TO_CHAR(SYSDATE, 'YYYYMMDD')
                    , EXETM = TO_CHAR(SYSDATE, 'HH24MISS')
            WHERE   1=1
            AND     MANDT = #G_MANDT#
            AND     CPUDT = TO_CHAR(SYSDATE, 'YYYYMMDD')
            AND     BUDAT = #BUDAT#
            AND     LIFNR = #LIFNR#
            AND     WERKS = #WERKS#
            AND     MATNR = #MATNR#
            AND     BWART = '101'
            AND     WAERS = #WAERS#;
        END IF;
    END IF;  
END; 

 

반응형

'프로그래밍 > Oracle' 카테고리의 다른 글

[FUNCTION]GET_PROJ_END  (0) 2013.07.11
[FUNCTION]GET_ZERODATE  (0) 2013.07.11
[FUNCTION]SET_ZERODATE  (0) 2013.07.11
[FUNCTION]GET_JAJEA_BALJU  (0) 2013.07.11
[FUNCTION]GET_BUDAT  (0) 2013.07.11