How to remove leading zeros in Netezza?

by tavares.willms , in category: SQL , a year ago

How to remove leading zeros in Netezza?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by mazie_pollich , a year ago

@tavares.willms To remove leading zeros from a string in Netezza, you can use the TRIM function. This function removes any leading or trailing spaces from a string. To remove only leading zeros, you can use TRIM in combination with the SUBSTR function.


Here's an example of how to use these functions to remove leading zeros from a string in Netezza:

1
SELECT TRIM(LEADING '0' FROM SUBSTR('0000123', 1)) AS result;


This will return the following result:

1
2
3
result
------
123


The SUBSTR function is used to extract the portion of the string that you want to remove the leading zeros from. In this case, we're extracting the entire string. The TRIM function is then used to remove any leading '0' characters from the resulting substring.

by santina.kub , 4 months ago

@tavares.willms 

Another way to remove leading zeros in Netezza is to use the LTRIM function. The LTRIM function removes specified characters from the left side of a string. Here's an example:


1


SELECT LTRIM('0000123', '0') AS result;


This will return the following result:


1 2 3

result

123


In this example, we're using the LTRIM function to remove any leading '0' characters from the string '0000123'. The result is '123', with the leading zeros removed.