메뉴 건너뛰기

tnt_db

Oracle PL/SQL에서 ARRAY사용 예제

운영자 2002.09.17 20:25 조회 수 : 3254 추천:18

CREATE OR REPLACE PROCEDURE SP_SDA130_ADJ
     ( FDATE         IN VARCHAR2,
       TDATE         IN VARCHAR2,
       DEPT_CODE     IN VARCHAR2,
       CUST_CODE     IN VARCHAR2,
       EMPL_ID       IN VARCHAR2,
       CREATE_USER   IN VARCHAR2,
       MODIFY_USER   IN VARCHAR2,
       PC_IP         IN VARCHAR2,
       SLIP_NO   IN OUT VARCHAR2,
       SLIP_CNT  IN OUT NUMBER
     ) AS
TYPE   ARRTYP   IS TABLE OF NUMBER(05)
       INDEX BY BINARY_INTEGER;
II     BINARY_INTEGER := 0;
CNT    BINARY_INTEGER := 0;
V_ARR       ARRTYP;
V_DATE      VARCHAR2(08);
V_MON       VARCHAR2(06);
V_FDATE     VARCHAR2(08);
V_TDATE     VARCHAR2(08);
V_DEPT      VARCHAR2(06);
V_CUST      VARCHAR2(06);
V_EMPL      VARCHAR2(07);
V_CREATE    VARCHAR2(07);
V_MODIFY    VARCHAR2(07);
V_IP        VARCHAR2(20);
V_RSEQ      NUMBER;
--
V_AMT       NUMBER;
V_PRICE     NUMBER;
V_CNT       NUMBER(05);
V_NO        NUMBER(05);
V_SEQ       VARCHAR2(05);
V_SITE_CODE VARCHAR2(04);
V_SITE_NAME VARCHAR2(40);
BEGIN
    SELECT TO_CHAR(SYSDATE,'YYYYMMDD'),TO_CHAR(SYSDATE,'YYYYMM') INTO V_DATE,V_MON FROM DUAL;
    V_FDATE   := FDATE;
    V_TDATE   := TDATE;
    V_DEPT    := DEPT_CODE;
    V_CUST    := CUST_CODE;
    V_EMPL    := EMPL_ID;
    V_CREATE  := CREATE_USER;
    V_MODIFY  := MODIFY_USER;
    V_IP      := PC_IP;
--
    SELECT NVL(COUNT(DISTINCT CUST_CODE),0) CNT
    INTO   V_CNT
    FROM   PURCH
    WHERE  PURCH_DATE BETWEEN V_FDATE
                      AND     V_TDATE
    AND    DEPT_CODE  = V_DEPT
    AND    CUST_CODE  = DECODE(V_CUST,'!',CUST_CODE,V_CUST)
    AND    ITEM_CODE NOT IN ('GDR','GACTA','GFA')
    AND    PURCH_GUBUN   = '1'
    AND    ADJ_SLIP_NO IS NULL;
--
    II := 0;
    LOOP
      II:=II+1;
      EXIT WHEN II > V_CNT;
      V_ARR(II):=0;
      SP_GET_NO(V_DATE,'08',V_NO);
      V_ARR(II):=V_NO;
    END LOOP;
--
    SP_GET_SLIPNO(V_DATE,V_SEQ);
    SP_SET_SLIP_M_WORK(V_DATE,V_SEQ,V_DEPT,V_EMPL,'S08',V_CREATE,V_MODIFY,V_IP);
--
    SELECT A.BIZ_AREA_CODE,
           B.BIZ_AREA_NAME
    INTO   V_SITE_CODE,
           V_SITE_NAME
    FROM   DEPT A,
           BIZ_INFO B
    WHERE  A.DEPT_CODE     = V_DEPT
    AND    B.BIZ_AREA_CODE = A.BIZ_AREA_CODE;
--
    V_AMT:=0;
    SLIP_CNT:=0;
    II := 0;
    FOR I IN (SELECT A.CUST_CODE,
                     B.CUST_NAME,
                     SUM(A.PRICE) PRICE,
                     SUM(A.VAT)   VAT
              FROM   PURCH A,CUST B
              WHERE  A.PURCH_DATE BETWEEN V_FDATE
                                  AND     V_TDATE
              AND    A.DEPT_CODE  = V_DEPT
              AND    A.CUST_CODE  = DECODE(V_CUST,'!',A.CUST_CODE,V_CUST)
              AND    A.ITEM_CODE NOT IN ('GDR','GACTA','GFA')
              AND    A.ADJ_SLIP_NO IS NULL
              AND    A.PURCH_GUBUN   = '1'
              AND    B.CUST_CODE(+) = A.CUST_CODE
              GROUP BY A.CUST_CODE,B.CUST_NAME)

    LOOP
        II:= II+1;
        SLIP_CNT:=SLIP_CNT+1;
        V_AMT := V_AMT + I.VAT;
        SP_SET_SLIP_D_WORK(V_DATE,V_SEQ,0,'D',V_DEPT,'1114600','2110101',I.VAT,V_CREATE,V_MODIFY,V_IP,V_RSEQ) ;
        SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'14',TO_CHAR(I.PRICE),'');
        SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'28',V_SITE_CODE,V_SITE_NAME);
        SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'29','02','세금계산서[일   반]');
        SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'37',I.CUST_CODE,I.CUST_NAME);
        SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'38','구매부가세(국내)','');
--
        V_NO := V_ARR(II);
        SP_SET_SURTAX('1',V_MON,V_NO,V_DATE,V_DATE,V_SEQ,V_RSEQ,'21',V_SITE_CODE,I.CUST_CODE,I.CUST_NAME,
                      '','','','','','','',
                      V_DEPT,'','',V_CREATE,V_MODIFY,V_IP);
        FOR J IN (SELECT ROWNUM RNO,
                         B.ACCT_ITEM_CODE,B.REP_ITEM_NAME,
                         C.UNIT,A.PURCH_QTY,A.PRICE,A.UPRICE,A.VAT
                  FROM   PURCH A,
                         REP_ITEM B,
                         ITEM C
                  WHERE  A.PURCH_DATE BETWEEN V_FDATE
                                      AND     V_TDATE
                  AND    A.DEPT_CODE  = V_DEPT
                  AND    A.CUST_CODE  = I.CUST_CODE
                  AND    A.ITEM_CODE NOT IN ('GDR','GACTA','GFA')
                  AND    A.ADJ_SLIP_NO IS NULL
                  AND    A.PURCH_GUBUN   = '1'
                  AND    C.ITEM_CODE     = A.ITEM_CODE
                  AND    B.REP_ITEM_CODE = C.REP_ITEM_CODE
                  AND    B.DOMAIN_GUBUN  = C.DOMAIN_GUBUN)
        LOOP
            IF J.RNO=1 THEN
               SP_SET_SURTAX_ITEMS('1',V_MON,V_NO,1,J.REP_ITEM_NAME,J.PRICE,J.VAT,J.UPRICE,J.PURCH_QTY,V_CREATE,V_MO DIFY,V_IP);
            ELSE
               EXIT;
            END IF;
        END LOOP;
    END LOOP;
    SP_SET_SLIP_D_WORK(V_DATE,V_SEQ,0,'C',V_DEPT,'2110101','1114600',V_AMT,V_CREATE,V_MODIFY,V_IP,V_RSEQ) ;
    SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'36','105184','영업부');
    SP_SET_SLIP_INFO_WORK(V_DATE,V_SEQ,V_RSEQ,'38','구매부가세(국내)','');
    SP_SAVE_SLIP(V_DATE,V_SEQ,'S08');
--
    UPDATE PURCH
    SET    ADJ_SLIP_NO = V_DATE||V_SEQ
    WHERE  PURCH_DATE BETWEEN V_FDATE
                      AND     V_TDATE
    AND    DEPT_CODE  = V_DEPT
    AND    CUST_CODE  = DECODE(V_CUST,'!',CUST_CODE,V_CUST)
    AND    ITEM_CODE NOT IN ('GDR','GACTA','GFA')
    AND    ADJ_SLIP_NO IS NULL
    AND    PURCH_GUBUN   = '1';
--
    SLIP_NO := V_DATE||V_SEQ;
    SLIP_CNT := SLIP_CNT+1;
--    
    COMMIT;
EXCEPTION
     WHEN OTHERS THEN
     RAISE_APPLICATION_ERROR(-20001,SQLCODE||SQLERRM);
END;
위로