Oracle除数为0

m0_59446386 2022-01-28 11:42:18

比如这种问题怎么处理(a/(b/c))其中B和C都有可能为0

实际问题是这跟1/(round((sum(g.goodsqty*h.unitprice))/(e.dtlgoodsqty*f.unitprice),2))

其中e.dtlgoodsqty*f.unitprice可能为0

g.goodsqty*h.unitprice也可能为0

最开始我是这样写的  但是没用decode((e.dtlgoodsqty*f.unitprice),0,0,(round(1/(round((sum(g.goodsqty*h.unitprice))/(e.dtlgoodsqty*f.unitprice),2)),2)*100))

...全文
371 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
DarkAthena 2022-02-18
  • 打赏
  • 举报
回复

还有,发问题干嘛不走问答板块,现在社区帖子看的人太少了

DarkAthena 2022-02-18
  • 打赏
  • 举报
回复

方法一

case when e.dtlgoodsqty*f.unitprice=0 or sum(g.goodsqty*h.unitprice) =0 then null
  else 
1/(sum(g.goodsqty*h.unitprice))/(e.dtlgoodsqty*f.unitprice))
end

方法二

1/(decode(sum(g.goodsqty*h.unitprice),0,null))/decode((e.dtlgoodsqty*f.unitprice),0,null)

除了判断你这两个乘积可能除数为0的情况,还要注意一下,可能会出现round前不为0,但round后为0的情况,如果非得在分母里round,那还是在case when 里再加个条件吧,太长了

yaiger 2022-02-08
  • 打赏
  • 举报
回复

a/(b/c) = ac/b = ac/nullif(b,0)

yaiger 2022-02-07
  • 打赏
  • 举报
回复

试试nullif函数

m0_59446386 2022-02-07
  • 打赏
  • 举报
回复

求解啊!!!!

17,134

社区成员

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

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