Padding the beginning of a mysql INT field with zeroes

后端 未结 2 1601
余生分开走
余生分开走 2020-12-18 03:56

I have an INT field in a large MySQL database containing incremental numbers in an INT field. These numbers are currently regular autoincrement numbers (1, 2, 3) but I need

2条回答
  •  清歌不尽
    2020-12-18 04:37

    You can add a ZEROFILL attribute to the column to pad the data in the database or, when querying,

    SELECT LPAD(CONVERT(`col`,VARCHAR(3)),3,'0')
    

    to retreive the data formatted as a 3 digit number

提交回复
热议问题