Q:

LPAD without trimming in mysql

I am trying to find a way to add 0 at the beginning of an ID without trimming it :
I am currently using LPAD(id,4,"0") witch works fine until 9999

Request : SELECT LPAD(12345,4,"0");
Excepted result : 12345
Result : 1234

I am Looking for a Request who does LPAD(id, MAX(LENGTH(id),4), "0")
I found SELECT IF(LENGTH(12345)>4, 12345, LPAD(12345, 4, "0")); but i would prefer if the 4 was in a single place (to make it easier use it elsewhere).

Is there a build-in function that does what i'm looking For ?
Or is there an alternative to the function MAX() that would work in that situation ?
Or should I stick with the IF(LENGTH) solution and it's drawbacks ?

Edit :
ZEROFILL doesn't fit my needs because I also need the id without 0s.
I mainly use the ID without the LPAD(), but when I do, I use it with a prefix : CONCAT("PFX", LPAD(id,4,"0"))
Thanks for your Help
PS: please tell me if i do anything wrong, it's my first time asking here.

A:

Ask yourself, why a number would need leading zeroes at all. No number in practical and theoretical math needs leading zeroes.
Maybe you want to visuals something, and not work with the result as a real number.
In that case, you can either declare the field in the table ZEROFILL and select it converted to char: SELECT CONVERT(id, CHAR);.
Other than that, the only way is a mix of CONCAT() and LENGTH(), that way you avoid stripping the ID to the value in LPAD().

