1 row affected (0.00 sec) mysql> SELECT identifier FROM int_table01 WHERE name like "現場猫"; +------------+ | identifier | +------------+ | 12345678 | ←9文字にならない! +------------+ 1 row in set (0.02 sec)
CREATE TABLE `int_table02` ( `id` INT NOT NULL AUTO_INCREMENT, `identifier` INT(9) ZEROFILL NOT NULL, `name` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARACTER SET = utf8mb4;
1 row affected (0.00 sec) mysql> SELECT identifier FROM int_table02 WHERE name like "現場猫"; +------------+ | identifier | +------------+ | 012345678 | ←先頭が0で埋められている! +------------+ 1 row in set (0.00 sec)
SELECT LPAD(identifier,9,0) FROM int_table01 WHERE name like "現場猫"; +----------------------+ | LPAD(identifier,9,0) | +----------------------+ | 012345678 | ←先頭が0で埋められている! +----------------------+ 1 row in set (0.00 sec)