Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you fill in or pad a column with zeros with a MySQL query?

Tags:

sql

mysql

I've got a large table (~10,000) and I need one column to take up exactly three spaces. It almost always only takes up one space, but I need the other two spaces to be filled in with zeros (it's an integer column). is there a function for that?

like image 612
btelles Avatar asked Dec 18 '22 04:12

btelles


2 Answers

Why would you do this? If it is because you want some report that queries the table to display one digit values as 3 digits, add the padding zeroes when you display it. Don't mix display information into your data.

like image 156
Brian Schroth Avatar answered Jan 22 '23 22:01

Brian Schroth


Add ZEROFILL attribute to the int column.

like image 26
Tomas Avatar answered Jan 22 '23 22:01

Tomas