1、在存储程序中使用非 SELECT SQL 语句(可以向表中添加/修改/删除数据) create table t1(id int ,name varchar(20));
create procedure insert_data(in count int) begin declare i int default 0; repeat set i=i+1; insert into t1(id,name) values(i,concat('name-',i)); until i=10 end repeat; end$$
2、把表中的数据读入本地变量(使用select-into语法结构) create procedure use_select_into() begin declare count int default 0; select count(1) into count from t1; select concat('==>',count); end$$
create procedure use_select_into2() begin declare row_id int default 0; declare row_name varchar(20) default ''; declare i int default 0;
while i<=10 do set i=i+1; select id,name into row_id,row_name from t1 where id = i; select concat('[',i,'] id=',row_id,' name=',row_name); end while; end$$