trim impala 中的前导零
trim leading zeros in impala
我有两种账号,都是字符串:
其中一些具有 leading zeros
,其他已正确导入并且没有前导零;
如何在不修剪正常帐号的情况下去掉前导零?
带前导零的有点:
0000012345678
没有前导零的是:
1345678
如何在 Impala 中做到这一点而不删除所有帐号?据我所知,在那些带有前导零的记录中总是有 5 个前导零。
试试这个:
SELECT CAST( "0000012345678" AS INT);
或
SELECT regexp_replace( "0000012345678","^0+(?!$)","")
尝试使用 REGEXP_REPLACE
:
SELECT REGEXP_REPLACE('0000012345678', '^0*', '') AS number_out
FROM yourTable;
你可以使用substr()
select case when left(accountno)='00000' then substr(accountno,6,length(accountno)-5)
else accountno end
from yourtablename
我有两种账号,都是字符串:
其中一些具有 leading zeros
,其他已正确导入并且没有前导零;
如何在不修剪正常帐号的情况下去掉前导零?
带前导零的有点:
0000012345678
没有前导零的是:
1345678
如何在 Impala 中做到这一点而不删除所有帐号?据我所知,在那些带有前导零的记录中总是有 5 个前导零。
试试这个:
SELECT CAST( "0000012345678" AS INT);
或
SELECT regexp_replace( "0000012345678","^0+(?!$)","")
尝试使用 REGEXP_REPLACE
:
SELECT REGEXP_REPLACE('0000012345678', '^0*', '') AS number_out
FROM yourTable;
你可以使用substr()
select case when left(accountno)='00000' then substr(accountno,6,length(accountno)-5)
else accountno end
from yourtablename