oracle - 字符到数字转换错误

标签 oracle plsql oracle10g

declare
   l_tot number := 0;

begin
   for i in 1..apex_application.g_f08.count loop
      l_tot := l_tot + nvl(to_number(apex_application.g_f08(i)),0);
   end loop;

 if l_tot = nvl(to_number(:P21_TOTAL_PRICE),0) then
      return true;
   else
      return false;
   end if;
end;

上面的代码出现以下错误

ORA-06502: PL/SQL: numeric or value error: character to number conversion error

:P21_TOTAL_PRICE 发生错误。怎么了?我该如何纠正这个问题?

最佳答案

与其使用 REPLACE,不如使用更强大的 REGEXP_REPLACE 函数。 http://www.orafaq.com/wiki/REGEXP_REPLACE

然后您可以使用 TO_NUMBER 函数从字符串中删除任何非数字字符。

在你的情况下它会是这样的:

REGEXP_REPLACE(:P21_TOTAL_PRICE, '[^0-9]+', ''); 

在这里查看我对几乎完全相同问题的回答:Oracle To_Char function How to handle if it's already a string

关于oracle - 字符到数字转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9074589/

相关文章:

sql - 如何找出导致 Oracle 死锁的原因

oracle - 运行运行其他脚本文件的 SQL*Plus 脚本

oracle - Oracle NUMBER 类型是否可能溢出?

java - 如何在 PL/SQL 存储过程中返回自定义集

eclipse - 在 Hibernate 中更改数据库时出现问题

c# - 在依赖 Oracle 的 Windows 启动时自动启动 Windows 服务

sql - 在 SQL 中连接两个字符串列时如何忽略尾部斜杠

sql - 甲骨文 : Dynamic column name

java - 如何在oracle10g数据库中选择名称?

sql - 使用Alter命令的Oracle存储过程