SQL 如何在netezza中将字符串转换为数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26059163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert string into number in netezza
提问by ihsansat
i have table_1 include some field, one field name is THROUGHPUT in char datatype(the value is number)
我有 table_1 包含一些字段,一个字段名称是 char 数据类型中的 THROUGHPUT(值为数字)
i want to use function avg() to get average value from all THROUGHPUT value in netezza,
我想使用函数 avg() 从 netezza 中的所有 THROUGHPUT 值中获取平均值,
i have tried code for convert to float :
我试过转换为浮点数的代码:
SELECT Cast(THROUGPUT as float) AS A
FROM WIFI.WID_NM_DETAIL
ORDER BY A
when i execute the code, i have error ERROR: Bad float8 input format '1,248.2',
当我执行代码时,出现错误 ERROR: Bad float8 input format '1,248.2',
i tried to another datatype, but still error
我尝试了另一种数据类型,但仍然出错
How can i fix it ?
我该如何解决?
Thx
谢谢
采纳答案by sqlab
Depending what kind of format mask you use for displaying your throughput and what locale for your database you should either remove all commas or all dots. Assuming that the comma here separates the thousands, you can try one of these
根据您用于显示吞吐量的格式掩码类型以及数据库的语言环境,您应该删除所有逗号或所有点。假设这里的逗号分隔千位,您可以尝试其中之一
CAST(REPLACE(throughput, '.', '') AS FLOAT)
or
或者
CAST(TRANSLATE(throughput, ',', '') AS FLOAT)