hive-去字符串前导0
hive-去字符串前导0
- leading:去掉字段串前的0
- TRAILING:去掉字段串后的0
- BOTH:去掉字段串前后的0
0的数量可以是不确定个数,也可以用这种方法去掉某些字符前缀后缀
SELECT a,
trim(
leading '0'
FROM a
) AS c1,
trim(
BOTH '0'
FROM a
) AS c2,
trim(
TRAILING '0'
FROM a
) AS c3
FROM (
SELECT '010100100' AS a
UNION ALL
SELECT '10100100' AS a
UNION ALL
SELECT '0000010100100' AS a
UNION ALL
SELECT '00000a0100100' AS a
) t
输出结果
a c1 c2 c3
00000a0100100 a0100100 a01001 00000a01001
0000010100100 10100100 101001 00000101001
010100100 10100100 101001 0101001
10100100 10100100 101001 101001