SQLite function to format numbers with leading zeroes?

后端 未结 4 2033
清歌不尽
清歌不尽 2020-12-29 20:22

I’ve got an SQLite database that will need to contain products. Those products have a fixed-format composite product number, consisting of category, group and product numbe

4条回答
  •  萌比男神i
    2020-12-29 21:26

    Since 3.8.3 (2014) You can use printf as:

    SELECT printf('%04d', product_number) AS product_number FROM table;
    

    Change the 4 to however many digits you need. This would return 0001 for product_number 1.

提交回复
热议问题