Storing leading zeros of integers in MySQL database as INTEGER

后端 未结 4 384
渐次进展
渐次进展 2020-12-05 07:32

I need MySQL to store numbers in a integer field and maintain leading zeros. I cannot use the zerofill option as my current field is Bigint(16) and numbers can vary in amoun

4条回答
  •  春和景丽
    2020-12-05 08:07

    You can still sort the string(CHAR/VARCHAR) columns like integer using CAST

    ORDER BY CAST(`col_name` AS SIGNED) DESC
    

    So, you can store them in CHAR/ VARCHAR type fields.

提交回复
热议问题