hive> SELECT regexp_replace( "00000012300234","^0+(?!$)","") ;
OK
12300234
Time taken: 0.156 seconds, Fetched: 1 row(s)
hive> SELECT regexp_replace( "000000","^0+(?!$)","") ;
OK
0
Time taken: 0.157 seconds, Fetched: 1 row(s)
hive> SELECT regexp_replace( "0","^0+(?!$)","") ;
OK
0
Time taken: 0.12 seconds, Fetched: 1 row(s)
或使用 CAST -转换为int到string:
hive> SELECT CAST(CAST( "00000012300234" AS INT) as string);
OK
12300234
Time taken: 0.115 seconds, Fetched: 1 row(s)
hive> SELECT CAST( "00000012300234" AS INT);
OK
12300234
Time taken: 0.379 seconds, Fetched: 1 row(s)
hive>
2条答案
按热度按时间uyhoqukh1#
您可以通过以下方式实现:
regexp_replace
字符串函数regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)
下面将删除前导零,但在必要时保留一个(即,它不会将“0”变成空白字符串)。或使用
CAST
-转换为int到string:js4nwp542#
什么都不做只是把字符串转换成int
它将返回12300234