1. 程式人生 > 實用技巧 >SQL-002以舊換新傳財務憑證核對

SQL-002以舊換新傳財務憑證核對

/* Formatted on 2020/11/13 11:38:36 (QP5 v5.326) */
DECLARE
    /*以下定義開始日期,每次查詢時請自行修改*/
    startdate                 CHAR (10) := '2020-10-01';


    /*  以下語句請切記不要改動!!!!!!!!!!!!!!!!!! */
    v_dap_finindex            dap_finindex%ROWTYPE;
    v_dtjt_tradein            dtjt_tradein_h%ROWTYPE;
    endDate                   CHAR (
10) := '2022-12-31'; CURSOR c_dtjt_tradein IS SELECT H.* FROM dtjt_tradein_h h INNER JOIN dtjt_tradein_b b ON h.ctradeinhid = b.ctradeinhid --2020-11-15更新,增加dtjt_tradein_b WHERE NVL (h.dr, 0) = 0 AND NVL (b.dr, 0) = 0 AND h.vbillstatus
= 1 AND h.vdef2 IS NULL AND H.dbilldate >= startdate AND H.dbilldate <= endDate for update of vdef2 nowait; num INT := 0; i INT := 0; v_dtjt_vdef2 dtjt_tradein_h.vdef2%TYPE; v_dtjt_vbillcode dtjt_tradein_h.vbillcode
%TYPE; v_dtjt_pk_corp dtjt_tradein_h.pk_corp%TYPE; v_dap_finindex_billcode DAP_FININDEX.BILLCODE%TYPE; v_dap_finindex_pk_corp dap_finindex.pk_corp%TYPE; v_dtjt_dbilldate dtjt_tradein_h.dbilldate%TYPE; BEGIN SELECT TO_CHAR (SYSDATE, 'yyyy-mm-dd') INTO endDate FROM DUAL; DBMS_OUTPUT.put_line ( '以舊換新工單傳財務憑證驗證,檢查日期範圍:' || startdate || ' -- ' || endDate); IF NOT c_dtjt_tradein%ISOPEN THEN OPEN c_dtjt_tradein; END IF; NULL; LOOP FETCH c_dtjt_tradein INTO v_dtjt_tradein; EXIT WHEN c_dtjt_tradein%NOTFOUND; v_dtjt_vdef2 := v_dtjt_tradein.vdef2; v_dtjt_vbillcode := v_dtjt_tradein.vbillcode; v_dtjt_pk_corp := v_dtjt_tradein.pk_corp; v_dtjt_dbilldate := v_dtjt_tradein.dbilldate; v_dap_finindex_billcode := v_dtjt_vbillcode; v_dap_finindex_pk_corp := v_dtjt_pk_corp; SELECT COUNT (billcode) INTO num FROM dap_finindex WHERE (billcode = v_dap_finindex_billcode) AND (pk_corp = v_dap_finindex_pk_corp) AND (billcode IS NOT NULL) AND (busidate >= startdate) AND (busidate <= endDate) AND (pk_sys = 'BSM' AND pk_proc = 'JT01') -- and (flag=2) 這一行需要驗證一下再決定是否使用!!!!!!!!! AND (NVL (dr, 0) = 0); IF (num <> 1) THEN i := i + 1; UPDATE dtjt_tradein_h SET vdef2=null,vdef3=v_dtjt_vdef2 WHERE current of c_dtjt_tradein; IF (i < 10) THEN DBMS_OUTPUT.put_line ( '檢查結果顯示:No:0' || i || ',工單日期:' || v_dtjt_dbilldate || ' ,公司:' || v_dtjt_pk_corp || ',可能未傳遞單號: ' || v_dtjt_vbillcode); ELSE DBMS_OUTPUT.put_line ( '檢查結果顯示:No:' || i || ',工單日期:' || v_dtjt_dbilldate || ' ,公司:' || v_dtjt_pk_corp || ',可能未傳遞單號: ' || v_dtjt_vbillcode); END IF; END IF; END LOOP; IF c_dtjt_tradein%ISOPEN THEN CLOSE c_dtjt_tradein; END IF; IF (i < 1) THEN DBMS_OUTPUT.put_line ( '以舊換新工單傳財務憑證驗證正常,放心使用'); ELSE DBMS_OUTPUT.put_line ( '以舊換新工單傳財務憑證驗證完畢,可能未傳遞總數量:' || i); END IF; END; /