且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DB2:将varchar转换为货币

更新时间:2021-10-22 15:15:17

这真的很容易...效果很好...

It really is that easy...this works fine...

select cast('10.15' as decimal(9,2)) - 1
from sysibm.sysdummy1;

您的数据中除了有效的数字字符外,还有其他内容.除了前导或尾随空格...

You've got something besides a valid numerical character in your data.. And it's something besides leading or trailing whitespace...

尝试以下操作...

select *
from table 
where translate(column1, '           ','0123456789.')
      <> ' '
     or translate(column2, '           ','0123456789.')
      <> ' '

这将向您显示带有字母字符的行...

That will show you the rows with alpha characters...

如果上面没有返回任何内容,则您可能有一个带双小数点或其他内容的字符串...您可以使用正则表达式找到那些.

If the above does't return anything, then you've probably got a string with double decimal points or something... You could use a regex to find those.