这个CASE语句怎么写。

beyondflight 2007-07-25 11:25:48
info 表中有a字段,其类型为VARCHAR2(),值为20.5,30.1等数据,业务逻辑要求合计该字段,同时要求150封顶,SQL如何写?
select case when sum(a) > 150 then '150' else sum(a) end as A from info

以上语句在else sum(a)处报“数据类型不一致”错误!
...全文
130 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
beyondflight 2007-07-25
  • 打赏
  • 举报
回复
谢谢,结贴前再问一下,如果前面就写成'150封顶',那么后面的else sum(a)如何改?
hongqi162 2007-07-25
  • 打赏
  • 举报
回复
'150' 与 else sum(a) 的结果类型不一致导致的错误

jacobrong79 2007-07-25
  • 打赏
  • 举报
回复
select case when sum(a) > 150 then 150 else sum(a) end as A from info
jacobrong79 2007-07-25
  • 打赏
  • 举报
回复
如果前面就写成'150封顶',那么后面的else sum(a)如何改?
select case when sum(a) > 150 then '150封顶' else to_char(sum(a)) end as A from info
yugas 2007-07-25
  • 打赏
  • 举报
回复
问题在于sum函数中不能使用varchar2类型的字段
select case when sum(to_number('20')) > 19 then 'yes' else 'no' end ship_no from dual;

你的:
select case when sum(to_number(a)) ) > 150 then '150' else sum(to_number(a)) )end as A from info

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧