ITPub博客

首页 > 数据库 > Oracle > Oracle将数值转化成负数的写法

Oracle将数值转化成负数的写法

原创 Oracle 作者:feelpurple 时间:2016-03-18 19:02:29 0 删除 编辑
最近使用PL SQL在写报表存储过程的时候,需求人员提出要将提现金额写成负值的形式
最初的写法如下:

--计算提现金额
update elmp_daily_fund
   set WITHDRAW_AMOUNT =
       (select to_number('-' || (sum(l.amount) / 100))
          from mis.ELMP_REPORT_CHARCASHFILL@db_mis l
         where l.countdate >= begin_date
           and l.countdate < begin_date + 1
           and l.reporttype = 1
           and status = 0)
 where REPORT_DATE = begin_date;

报表JOB运行了几天,出现报错,ORA-01722 invalid number

查询了一下论坛,发现有朋友问同样的问题
解决方法是直接使用 - 和 abs 函数,更改后的SQL如下:

--计算提现金额
update elmp_daily_fund
   set WITHDRAW_AMOUNT =
       (select -abs(sum(l.amount) / 100)
          from mis.ELMP_REPORT_CHARCASHFILL@db_mis l
         where l.countdate >= begin_date
           and l.countdate < begin_date + 1
           and l.reporttype = 1
           and status = 0)
 where REPORT_DATE = begin_date;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26506993/viewspace-2059684/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-08-01

  • 博文量
    404
  • 访问量
    1673977