I have a column in a MySQL database which is currently all different lengths an example would be –
Reference (Column Name)
12930
1829
892
182902
I need them all to be 12 characters long with 0’s added to the front to make them that length, so they example above would need to become –
Reference (Column Name)
000000012930
000000001829
000000000892
000000182902
Is there an SQL query I can run to do this, if not what would the best way to do this be?
use
zerofillif you use numbers (int, bigint, float etc…)if you use varchar or char, you have to use PHP str_pad: