如何在MySQL中将前导零添加到不同的字符长度?

问题描述:

我对一个不同的表有一个查询,而且所有表的长度都不同,这要求ID的前导零.是否可以使用一个查询来将前导零添加到任何表?

Hi,I have one query for different tables and all of them have different length which requires leading zero for the ID. Is it possible to use one query that will add leading zero to any table?

让我们说第一个查询为insert to tbl1_field1(CHAR 3) 001,然后下一个查询为insert to tbl2_field2(CHAR 4) 0001,然后下一个为insert to tlb3_field3(CHAR 10) 0000000001.我正在使用php and mysql

lets say first query is insert to tbl1_field1(CHAR 3) 001, then next query is insert to tbl2_field2(CHAR 4) 0001 then next is insert to tlb3_field3(CHAR 10) 0000000001. I am using php and mysql

您可以使用查询将显示类似这样的字符串-'0001'.

the query will show a string like this - '0001'.