最近使用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博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-2059684/,如需转载,请注明出处,否则将追究法律责任。