1.查看存储过程
show procedure status;
2.删除存储过程
drop procedure 存储过程名称
3.创建存储过程
1 create procedure p1() 2 begin 3 select * from table; 4 end; 5 6 call p1(); 7 8 create procedure p2(n int) 9 begin 10 select * from table where num>n; 11 end; 12 13 call p2(2); 14 15 16 create procedure p3(n int,j char(1)) 17 begin 18 if j=‘a‘ then 19 select * from table where num>n; 20 else 21 select * from table where num<n; 22 end if; 23 end; 24 25 call p3(2,‘a‘); 26 27 28 #计算1->n的和 29 create procedure p4(n smallint) 30 begin 31 declare i int; 32 declare sum int; 33 set i = 1; 34 set sum = 0; 35 while i <= n do 36 set sum = sum+i; 37 set i = i+1; 38 end while; 39 select sum; 40 end; 41 call p4(100);
4.调用存储过程
call 存储过程名称();