用单个变量替换同一组变量

时间:2014-01-17 10:16:14

标签: sql oracle

我希望用一组变量替换所有%variable1%, %variable2%, %variable3%, %variable4%而不重复调用相同的参数大小固定在我的程序上,是否有任何进程可以通过SQL查询来完成?

SELECT 
    b.cons_no, b.NAME , b.cat_cd, b.bill_no, b.bill_date, 
FROM 
    (SELECT 
         a.cons_cd cons_no, a.cons_name NAME, a.category_cd cat_cd,
         a.bill_no bill_no, TO_CHAR (a.proc_date, 'DD/MM/YYYY') 
         bill_date 
     FROM 
         mstcons_bill_print a, mstcons b
     WHERE 
         b.cons_cd = a.cons_cd
         AND due_date < TRUNC (SYSDATE)
         AND a.bill_no IN (
                  SELECT TO_CHAR (MAX (bill_no))
                  FROM mstcons_bill_print
                  WHERE cons_cd IN (
                              SELECT cons_cd
                              FROM mstcons x, mstdtc z
                              WHERE x.dtc_cd = z.dtc_cd
                                AND x.dtc_cd LIKE '%variable1%'
                                AND x.category_cd LIKE '%variable2%'
                                AND x.route LIKE '%variable3%'
                                AND z.feeder_cd LIKE '%variable4%')
                  GROUP BY cons_cd
                  MINUS
                  SELECT TO_CHAR (MAX (bill_no))
                  FROM trnpaymnt_dtls
                  WHERE cons_cd IN (
                              SELECT cons_cd
                              FROM mstcons x, mstdtc z
                              WHERE x.dtc_cd = z.dtc_cd
                                AND x.dtc_cd LIKE '%variable1%'
                                AND x.category_cd LIKE '%variable2%'
                                AND x.route LIKE '%variable3%'
                                AND z.feeder_cd LIKE '%variable4%')
                  GROUP BY cons_cd)) b,
       (SELECT   c.bill_no bill_no,
                 SUM (c.achd_cd) bill_net,
                 SUM (c.achd_cd) bill_paid
            FROM trncons_achd c
           WHERE c.achd_cd IN ('CURDMD', 'ARRE', 'CURINT', 'INTA')
            AND c.bill_no IN (
                    SELECT   TO_CHAR (MAX (bill_no))
                        FROM mstcons_bill_print
                       WHERE cons_cd IN (
                                SELECT cons_cd
                                  FROM mstcons x, mstdtc z
                                 WHERE x.dtc_cd = z.dtc_cd
                                   AND x.dtc_cd LIKE '%variable1%'
                                 AND x.category_cd LIKE '%variable2%'
                                 AND x.route LIKE '%variable3%'
                                 AND z.feeder_cd LIKE '%variable4%')
                    GROUP BY cons_cd
                    MINUS
                    SELECT   TO_CHAR (MAX (bill_no))
                        FROM trnpaymnt_dtls
                       WHERE cons_cd IN (
                                SELECT cons_cd
                                  FROM mstcons x, mstdtc z
                                 WHERE x.dtc_cd = z.dtc_cd
                                   AND x.dtc_cd LIKE '%variable1%'
                                 AND x.category_cd LIKE '%variable2%'
                                 AND x.route LIKE '%variable3%'
                                 AND z.feeder_cd LIKE '%variable4%')
                    GROUP BY cons_cd)
        GROUP BY c.bill_no) a
    WHERE a.bill_no = b.bill_no AND a.bill_net - a.bill_paid > 300;

0 个答案:

没有答案