Formatting values dynamically based on length

Viewed 23

I have input data as below

enter image description here

I want to add leading 0s to the PRODUCT_NUMBER to make it total 10 digit , desired output should be like below

enter image description here

Is there a way to do this in snowflake?

2 Answers

Another alternative is lpad which dynamically pads specified character until the string reaches the length N. If the length of string was > N to begin with, it will return first N characters and truncate the rest.

select lpad(col, 10, '0')

Documentation

Related