数据库教程 存储过程

数据库教程 存储过程
关于数据库存储过程的相关描述:
1、优点:性能强
2、缺点:无法移植
3、mysql 存放在函数类型中,不调用不会执行(存储过程需要单独调用)
参数类型:
in:传入参数
out:传出参数
intout:既可以传入又可以传出
-- 存储过程,不需要返回值
create procedure p_tese(in n int) begin -- 定义一个变量 declare a int default 1; declare s int default 0; -- 循环 while a <= n do set s = s + a; set s = s + 1; end while; update t_student set height = s where id =500; end
调用函数:call p_test(100)
实例二:
create procedure p_get_seudent_count(classid int) begin declare end_loop int default 1; declare v_classid int; declare v_height int; declare v_count int default 0; -- 定义游戏 declare cur cursor for select class_id,height from t_student where class_id = clasaid; -- 定义游标 到尾端,赋值end_loop为0 declare continue handler for not found set end_loop = 0; -- 打开游标 open cur; while end_loop = 1 do fetch cur into v_classid,v_height; if v_height > 170 then set v_count = v_count +1; end if; end while; update t_class set student_cut = v_count where id =classidl close cur; end
本文作者:刘广法,转载注明出处。