首页 > 数据库技术 > 详细

Mysql存储过程简明使用

时间:2014-03-22 20:32:13      阅读:685      评论:0      收藏:0      [点我收藏+]

1.查看存储过程
show procedure status;

2.删除存储过程
drop procedure 存储过程名称

3.创建存储过程

bubuko.com,布布扣
 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);
bubuko.com,布布扣

4.调用存储过程
call 存储过程名称();

Mysql存储过程简明使用,布布扣,bubuko.com

Mysql存储过程简明使用

原文:http://www.cnblogs.com/ahwu/p/3617901.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!