Mysql 的存储函数
创建一个存储函数打印一个 “hello world”
程序体
create procedure sayhelloworld()
begin
select “hello world” ;
end;
调用
call sayhelloworld();
循环一个表中的数据
程序体
create procedure circulation()
begin
DECLARE s int DEFAULT 0;
DECLARE report_id varchar(255);
DECLARE ids CURSOR FOR select id from institute; – 定义一个游标的循环体
DECLARE CONTINUE HANDLER FOR NOT FOUND SET s=1; – 游标结束时赋值是=1
open ids; – 打开游标
fetch ids into report_id; – 开始循环游标
WHILE s<>1 DO
select report_id;
fetch ids into report_id;
end while;
close ids;
END;
调用
call circulation();