我正在使用 Hive 0.13,表值的 STRING 列中有 1.250,99
我想将这些值转换为十进制,所以我必须替换“。”通过“”和“,”通过“。”结果是 1250.99
这是我的 hql 句子:
cast(regexp_replace(regexp_replace(price, '\\.',''), ',','.') as decimal(18,6))
但它返回 NULL,我想是因为转换没有成功。有什么问题吗?
如果我不进行转换,它将返回预期的字符串。
更新
我的问题是该列中有空格,因此无法将其转换为十进制值。在进行转换之前我已经使用了修剪功能。
试试这个:
select cast(regexp_replace(regexp_replace('1.234,56','\\.',''),'\,','\.') as decimal(10,2));