MySql 存储过程和触发器_mysql存储过程和触发器-CSDN博客文章浏览阅读162次。MySql存储过程、存储函数和触发器_mysql存储过程和触发器https://blog.csdn.net/chenniorange/article/details/132376605存储过程例子
-- A. 定义局部变量, 记录累加之后的值;
-- B. 每循环一次, 就会对n进行-1 , 如果n减到0, 则退出循环 ----> leave xx
 
create procedure p9(in n int)
 
begin
 
 declare total int default 0;
 
 sum:loop
     if n<=0 then
         leave sum;
     end if;
 
     set total := total + n;
     set n := n - 1;
 end loop sum;
 
select total;
 
end;
 
call p9(100);存储函数例子
create function fun1(n int) returns int deterministic begin declare total int default 0; while n>0 do set total := total + n; set n := n - 1; end while; return total; end; select fun1(50);
触发器例子
CREATE TRIGGER trigger_name 
BEFORE/AFTER INSERT/UPDATE/DELETE
 
ON tbl_name FOR EACH ROW -- 行级触发器
 
BEGIN
 trigger_stmt ; -- 触发器的具体逻辑
END;



















