简体   繁体   English

在黑斑羚上修剪前导零

[英]trim leading zeros in impala

I have two sorts of accounts number, all of which are strings: some of them have leading zeros , others have been imported properly and do not have leading zeros; 我有两种帐号,所有帐号都是字符串:其中一些有leading zeros ,另一些已正确导入,没有前导零;

How can I get rid of the leading zeros without trimming account numbers that are normal? 如何在不修剪正常帐号的情况下摆脱前导零?

the ones with leading zeros are somewhat: 0000012345678 带有前导零的那些是: 0000012345678

Those without leading zeros are: 1345678 没有前导零的那些是: 1345678

How can I do that in Impala without trimming all the account numbers?From what I have seen there are always 5 leading zeros in those records with leading zeros. 如何在不修剪所有帐号的情况下在Impala中执行此操作?从我所看到的情况下,这些记录中始终有5个前导零,其中前导零。

Try this: 尝试这个:

SELECT CAST( "0000012345678"  AS INT);

OR 要么

SELECT regexp_replace( "0000012345678","^0+(?!$)","")

Try using REGEXP_REPLACE : 尝试使用REGEXP_REPLACE

SELECT REGEXP_REPLACE('0000012345678', '^0*', '') AS number_out
FROM yourTable;

you can use substr() 你可以使用substr()

select case when left(accountno)='00000' then substr(accountno,6,length(accountno)-5)
else accountno end
from yourtablename

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM