使用LPAD()函数左键填充值。让我们首先创建一个表-
create table DemoTable -> ( -> Number int -> ); insert into DemoTable values(89696); insert into DemoTable values(89049443);
以下是更新多行和左填充值的查询-
update DemoTable set Number=LPAD(Number, 7, "9") where length(Number) < 7; Rows matched: 2 Changed: 2 Warnings: 0
让我们再次检查表记录-
select *from DemoTable;
输出结果
这将产生以下输出-
+----------+ | Number | +----------+ | 9857786 | | 9989696 | | 89049443 | +----------+ 3 rows in set (0.00 sec)