Oracle 11g查询报错:ORA-01722: 无效数字。求解!
Oracle11g查询报错:Oracle11g查询报错:ORA-01722:无效数字01722.00000-"invalidnumber"*Cause:Thespecif...
Oracle 11g查询报错:Oracle 11g查询报错:
ORA-01722: 无效数字
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.722. 00000 - "invalid number"
查询语句如下:
SELECT SUM(DECODE(TRUNC(TO_CHAR(hiredate,'year'),'yyyy'),'1980',1,0)) "1980",
SUM(DECODE(TRUNC(TO_CHAR(hiredate,'year'),'yyyy'),'1981',1,0)) "1981",
SUM(DECODE(TRUNC(TO_CHAR(hiredate,'year'),'yyyy'),'1982',1,0)) "1982"
FROM EMP
WHERE TRUNC(TO_CHAR(hiredate,'year'),'yyyy') IN ('1980','1981','1982');
求解! 展开
ORA-01722: 无效数字
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.722. 00000 - "invalid number"
查询语句如下:
SELECT SUM(DECODE(TRUNC(TO_CHAR(hiredate,'year'),'yyyy'),'1980',1,0)) "1980",
SUM(DECODE(TRUNC(TO_CHAR(hiredate,'year'),'yyyy'),'1981',1,0)) "1981",
SUM(DECODE(TRUNC(TO_CHAR(hiredate,'year'),'yyyy'),'1982',1,0)) "1982"
FROM EMP
WHERE TRUNC(TO_CHAR(hiredate,'year'),'yyyy') IN ('1980','1981','1982');
求解! 展开
展开全部
TRUNC没法处理字符串,只能处理时间和数字,建议用substr截取字符串吧
substr(string1,1,2)
string1 需要截取的字符串 1表示起始位置 2 表示截取长度
按理说TO_CHAR(hiredate,'year')就能直接用了,或者用TO_CHAR(hiredate,'yyyy')
substr(string1,1,2)
string1 需要截取的字符串 1表示起始位置 2 表示截取长度
按理说TO_CHAR(hiredate,'year')就能直接用了,或者用TO_CHAR(hiredate,'yyyy')
追问
谢谢。找到问题了,我把TO_CHAR和TRUNC位置写调了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询