CAST TEXT为INTEGER

时间:2015-12-28 13:04:48

标签: sql sqlite

我有一个CHAR列,其中包含对打印整数的杂乱OCR扫描。

我需要在该列上执行SUM()运算符。但是我无法正确投射。

;Good
sqlite> select CAST("123" as integer);
123

;No Good, should be '323999'
sqlite> select CAST("323,999" as integer);
323

我相信SQLite会将逗号解释为标记“the longest possible prefix of the value that can be interpreted as an integer number

的结尾

我更喜欢避免编写python脚本来对此列进行数据清理的痛苦。是否有任何聪明的方法严格使用SQL?

1 个答案:

答案 0 :(得分:2)

如果您尝试忽略逗号,请在转换前将其删除:

select cast(replace('323,999', ',', '') as integer)
相关问题