I have an INT field in my table, which I’d like to select as a zero-padded string. So for example, 8 would come out as 008, 23 as 023 and so on. Is this possible in a MySQL query?
I have an INT field in my table, which I’d like to select as
Share
You’re looking for the
LPADfunction:Edit:
As pointed out by @Brad in the comments, you could also define the column with ZEROFILL:
This would always produce at least 3 digit numbers (It would zero-pad numbers less than 3 digits, and not effect those more). It’s useful if you always need the numbers to come out like that (And not just in one query)…