Remove leading zeros using HiveQL

2019-07-22 16:13发布

问题:

I have a string value in which i might have leading zero's, so i want to remove all leading zeros.

For example:

accNumber = "000340" ---> "340"

Any UDF is available in Hive? can we use regexp_extract for this?

回答1:

Yes, just use REGEXP_REPLACE().

SELECT some_string,
   REGEXP_REPLACE(some_string, "^0+", '') stripped_string
FROM db.tbl

(fixed simple typo with comma)



标签: hive hiveql