1.直接上sql语句
drop PROCEDURE IF EXISTS xu;
CREATE PROCEDURE `xu`()
BEGIN
set @tnum = null; -- 设置变量接受表的数据量
select count(*) into @tnum from user; -- 将表的数据量赋值给变量
add_loop:loop -- 创建循环add_loop
if @tnum < 1000 THEN -- 判断表中是否小于1000条数据
INSERT into USER(user_name) VALUES( CONCAT("user",@tnum+1) );
set @tnum = @tnum+1;
else
leave add_loop; -- 不满足条件后就跳出循环
end if; -- 必须结束if
end loop add_loop; -- 必须结束循环
select * from user; -- 打印出插入数据后的表的数据
END
2.需求
先判断表中数据是否超过1000,没有超过就补全到1000.
不管表中数据有多少都要打印出来