db2 cast函数_SQL数据库下载

数据库 (5) 2024-07-30 12:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说
db2 cast函数_SQL数据库下载,希望能够帮助你!!!。

DB2数据库:The length, precision, or scale attribute for column, distinct type, structured type, array type, attribute of structured type, routine, cast target type, type mapping, or global variable "VARCHAR" is not valid.. SQLCODE=-604, SQLSTATE=42611, DRIVER=3.61.75

上面的bug

CREATE PROCEDURE DSJYDD.TWO_YEAR_COMPARE          
(
IN V_POINTCODE VARCHAR(50)
)
DYNAMIC RESULT SETS 1 LANGUAGE SQL 

BEGIN
p1:begin
DECLARE REF_CURSOR CURSOR WITH RETURN TO CLIENT FOR 

SELECT TO_CHAR(S.WQTIME,'YYYY')||'年'||TO_NUMBER(TO_CHAR(S.WQTIME,'MM'))||'月'||TO_NUMBER(TO_CHAR(S.WQTIME,'DD'))||'日' YM,TO_CHAR(ADD_MONTHS(S.WQTIME,-12),'YYYY')LYY,TO_CHAR(S.WQTIME,'YYYY')YY,Q.VTYPE,Q.VNUM,Q.LVNUM FROM
(SELECT 
MAX(WQTIME) WQTIME,
SUM(DECODE(DATALEVEL,'优',VNUM,0)) VNUM1,
SUM(DECODE(DATALEVEL,'良',VNUM,0)) VNUM2,
SUM(DECODE(DATALEVEL,'轻度污染',VNUM,0)) VNUM3,
SUM(DECODE(DATALEVEL,'中度污染',VNUM,0)) VNUM4,
SUM(DECODE(DATALEVEL,'重度污染',VNUM,0)) VNUM5,
SUM(DECODE(DATALEVEL,'严重污染',VNUM,0)) VNUM6,

SUM(DECODE(DATALEVEL,'优',LVNUM,0)) LVNUM1,
SUM(DECODE(DATALEVEL,'良',LVNUM,0)) LVNUM2,
SUM(DECODE(DATALEVEL,'轻度污染',LVNUM,0))LVNUM3,
SUM(DECODE(DATALEVEL,'中度污染',LVNUM,0))LVNUM4,
SUM(DECODE(DATALEVEL,'重度污染',LVNUM,0))LVNUM5,
SUM(DECODE(DATALEVEL,'严重污染',LVNUM,0))LVNUM6

FROM
(
SELECT QUALITY DATALEVEL,
SUM(DECODE(TO_CHAR(A.TIMEPOINT,'YYYY'),TO_CHAR(B1.JZTIME,'YYYY'),1,0)) VNUM,
SUM(DECODE(TO_CHAR(A.TIMEPOINT,'YYYY'),TO_CHAR(ADD_MONTHS(B1.JZTIME,-12),'YYYY'),1,0)) LVNUM,
MAX(A.TIMEPOINT) WQTIME
 FROM  DSJYDD.AIR_CITYDAYAQI_PUBLISH A,
(SELECT  TO_DATE(TO_CHAR(MAX(B.TIMEPOINT),'YYYY')||'0101','YYYYMMDD') KSTIME,MAX(B.TIMEPOINT) JZTIME FROM DSJYDD.AIR_CITYDAYAQI_PUBLISH B) B1
WHERE  
 cast(A.CITYCODE as varchar)=V_POINTCODE
AND ((A.TIMEPOINT between B1.KSTIME and B1.JZTIME)
OR (A.TIMEPOINT between ADD_MONTHS(B1.KSTIME,-12) and ADD_MONTHS(B1.JZTIME,-12)))
GROUP BY A.QUALITY
)

) S ,TABLE(VALUES('优',VNUM1,LVNUM1),
('良',VNUM2,LVNUM2),
('轻度污染',VNUM3,LVNUM3),
('中度污染',VNUM4,LVNUM4),
('重度污染',VNUM5,LVNUM5),
('严重污染',VNUM6,LVNUM6))

AS Q(VTYPE,VNUM, LVNUM);
OPEN REF_CURSOR; 
END;
END
GO

DB2数据库上面的红色字体更改成char就能解决上面的bug了

今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

发表回复