获取sql查询的错误“(完整)年份必须介于-4713和+9999之间,而不是0”

时间:2015-05-27 18:52:04

标签: mysql sql toad

我收到错误“(完整)年份必须介于-4713和+9999之间,而不是0”无法理解为什么会出现此错误。

SELECT B.TST_CTR_CDE, C.DESCRIPTION,TO_CHAR(TO_DATE(B.CMPLT_DTE,'yyyymmdd'), 'MONTH') Month,
sum(decode(b.pass_sta,'1',1)) as passed,
sum(decode(b.pass_sta,'0',1)) as failed,
sum(decode(b.pass_sta, '0',1,'1',1)) as tot, 
extract(month from TO_DATE(B.CMPLT_DTE,'yyyymmdd')) Mon, 
extract(year from TO_DATE(B.CMPLT_DTE,'yyyymmdd')) year 

 FROM aei052 A,
aei053 B,
 aei006 C
 WHERE
 A.MNT_ACTN_CDE='A' 
 AND
 A.EXAMNE_SID=B.EXAMNE_SID
 AND
 TO_DATE(B.CMPLT_DTE,'yyyymmdd') BETWEEN TO_DATE('07/01/2012','mm/dd/yyyy') AND TO_DATE ('06/30/2013','mm/dd/yyyy')
AND B.CMPLT_STA=1 AND
B.TST_CTR_CDE = C.TST_CTR_ID AND rownum <10
GROUP BY B.TST_CTR_CDE,C.DESCRIPTION, 
TO_CHAR(TO_DATE(B.CMPLT_DTE,'yyyymmdd'), 'MONTH'), extract(year from TO_DATE(B.CMPLT_DTE,'yyyymmdd')),extract(month from TO_DATE(B.CMPLT_DTE,'yyyymmdd'))
ORDER BY TST_CTR_CDE, YEAR, MON;

1 个答案:

答案 0 :(得分:1)

显然,问题是:TO_DATE(B.CMPLT_DTE,'yyyymmdd')

以下查询可帮助您找到麻烦的值:

select b.cmplt_dte
from table2 B
where length(b.cmplt_dte) <> 8 or
      substr(b.complt_dte, 4) not between '1900' and '2100';