将字符串类型转换为整数 [英] Typecast string to integer
本文介绍了将字符串类型转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从一个在 Varchar 中有原始提要的表中导入数据,我需要将 varchar 中的一列导入到一个字符串列中.我尝试使用 <column_name>::integer
以及 to_number(<column_name>,'9999999')
但出现错误,因为有一些空字段,我需要将它们作为空或空检索到新表中.
I am importing data from a table which has raw feeds in Varchar, I need to import a column in varchar into a string column. I tried using the <column_name>::integer
as well as to_number(<column_name>,'9999999')
but I am getting errors, as there are a few empty fields, I need to retrieve them as empty or null into the new table.
推荐答案
疯狂猜测:如果你的值是一个空字符串,你可以使用 NULLIF 将其替换为一个 NULL:
Wild guess: If your value is an empty string, you can use NULLIF to replace it for a NULL:
SELECT
NULLIF(your_value, '')::int
这篇关于将字符串类型转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文