日期:2014-05-17 浏览次数:20958 次
CREATE OR REPLACE PROCEDURE SP_QRY_CWHZ(BEGDATE DATE,ENDDATE DATE) is begin INSERT INTO T_QRY_CWHZB(ID,ZSL,SJ,YCZJE,KYE) SELECT MAX(ID),COUNT(DISTINCT ZFHM),TO_CHAR(CZSJ,'YYYY-MM-DD'),SUM(NVL(CZJE,0)),SUM(NVL(CZHYE,0)) FROM T_RECHARGE WHERE ZFBZ='F' AND TO_CHAR(CZSJ,'YYYY-MM-DD') >= TO_CHAR(BEGDATE,'YYYY-MM-DD') AND TO_CHAR(CZSJ,'YYYY-MM-DD') <= TO_CHAR(ENDDATE,'YYYY-MM-DD') GROUP BY TO_CHAR(CZSJ,'YYYY-MM-DD'); UPDATE T_QRY_CWHZB SET DF=YCZJE,ZJE=YCZJE+KYE; end SP_QRY_CWHZ;
AND TO_CHAR(CZSJ,'YYYY-MM-DD') >= TO_CHAR(BEGDATE,'YYYY-MM-DD') AND TO_CHAR(CZSJ,'YYYY-MM-DD') <= TO_CHAR(ENDDATE,'YYYY-MM-DD')
CREATE OR REPLACE PROCEDURE SP_QRY_CWHZ(BEGDATE DATE, ENDDATE DATE) IS SQL VARCHAR2(200); BEGIN SQL := 'INSERT INTO T_QRY_CWHZB(ID,ZSL,SJ,YCZJE,KYE) SELECT MAX(ID),COUNT(DISTINCT ZFHM),TO_CHAR(CZSJ,''YYYY-MM-DD''),SUM(NVL(CZJE,0)),SUM(NVL(CZHYE,0)) FROM T_RECHARGE WHERE ZFBZ=''F'''; IF (BEGDATE IS NOT NULL AND ENDDATE IS NOT NULL) THEN SQL := SQL || ' AND TO_CHAR(CZSJ,''YYYY-MM-DD'') >= TO_CHAR(BEGDATE,''YYYY-MM-DD'') AND TO_CHAR(CZSJ,''YYYY-MM-DD'') <= TO_CHAR(ENDDATE,''YYYY-MM-DD'') GROUP BY TO_CHAR(CZSJ,''YYYY-MM-DD'')'; ELSE IF (BEGDATE IS NULL AND ENDDATE IS NOT NULL) THEN SQL := SQL || ' AND TO_CHAR(CZSJ,''YYYY-MM-DD'') <= TO_CHAR(ENDDATE,''YYYY-MM-DD'')'; ELSE IF (BEGDATE IS NOT NULL AND ENDDATE IS NULL) THEN SQL:=SQL||' AND TO_CHAR(CZSJ,''YYYY-MM-DD'') >= TO_CHAR(BEGDATE,''YYYY-MM-DD'')'; ELSE NULL; END IF ; execute immediate sql; UPDATE T_QRY_CWHZB SET DF=YCZJE,ZJE=YCZJE+KYE; commit; end SP_QRY_CWHZ;
------解决方案--------------------
CREATE OR REPLACE PROCEDURE SP_QRY_CWHZ(BEGDATE DATE, ENDDATE DATE) IS SQL VARCHAR2(200); BEGIN SQL := 'INSERT INTO T_QRY_CWHZB(ID,ZSL,SJ,YCZJE,KYE) SELECT MAX(ID),COUNT(DISTINCT ZFHM),TO_CHAR(CZSJ,''YYYY-MM-DD''),SUM(NVL(CZJE,0)),SUM(NVL(CZHYE,0)) FROM T_RECHARGE WHERE ZFBZ=''F'''; IF (BEGDATE IS NOT NULL AND ENDDATE IS NOT NULL) THEN SQL := SQL || ' AND TO_CHAR(CZSJ,''YYYY-MM-DD'') >= TO_CHAR(BEGDATE,''YYYY-MM-DD'') AND TO_CHAR(CZSJ,''YYYY-MM-DD'') <= TO_CHAR(ENDDATE,''YYYY-MM-DD'') GROUP BY TO_CHAR(CZSJ,''YYYY-MM-DD'')'; ELSE IF (BEGDATE IS NULL AND ENDDATE IS NOT NULL) THEN SQL := SQL || ' AND TO_CHAR(CZSJ,''YYYY-MM-DD'') <= TO_CHAR(ENDDATE,''YYYY-MM-DD'') GROUP BY TO_CHAR(CZSJ,''YYYY-MM-DD'')'; ELSE IF (BEGDATE IS NOT NULL AND ENDDATE IS NULL) THEN SQL:=SQL||' AND TO_CHAR(CZSJ,''YYYY-MM-DD'') >= TO_CHAR(BEGDATE,''YYYY-MM-DD'') GROUP BY TO_CHAR(CZSJ,''YYYY-MM-DD'')'; ELSE NULL; END IF ; UPDATE T_QRY_CWHZB SET DF=YCZJE,ZJE=YCZJE+KYE; END ;
------解决方案--------------------
--没有环境测试,你试下 如果有错误 把具体的错误信息发出来 CREATE OR REPLACE PROCEDURE SP_QRY_CWHZ(BEGDATE DATE,ENDDATE DATE) is begin IF(BEGDATE is NULL or ENDDATE is NULL) THEN --oracle判断是否为空不能用= 要用 is null dbms_output.put_line('没有给变量足够的值!'); else INSERT INTO T_QRY_CWHZB(ID,ZSL,SJ,YCZJE,KYE) SELECT MAX(ID),COUNT(DISTINCT ZFHM),TO_CHAR(CZSJ,'YYYY-MM-DD'),SUM(NVL(CZJE,0)),SUM(NVL(CZHYE,0)) FROM T_RECHARGE WHERE ZFBZ='F AND C