首页 > 数据库技术 > 详细

mysql概要(十五)存储过程

时间:2016-01-18 00:23:56      阅读:167      评论:0      收藏:0      [点我收藏+]

1.定义:

技术分享

2.查看所有存储过程:

show procedure status;

3.创建存储过程:

create procedure 存储过程名字(参数)

begin 

s1l语句;

end$             #重定义的结束标记($)

例子:

create procedure p1(n smallint,c char(1))
begin
   if c=‘u‘ then
      slelect * from b where number>n;
   else
       declare i int;                #声明变量
       declare sum int;
       set i = 1;                      #变量赋值
       set sum=0;
       while i < = n do 
         set sum = sum + i;
         set i = i + 1;
       end while;
        select sum;                 #输出值
    end if;
end$

4.存储过程的调用:

     call p1(100,‘u‘)$       #注意“$”只是结束标记  

5.删除存储过程

drop procedure 存储过程名字

 

6.函数function(略)

类似存储过程,但有返回值。

 

技术分享

 

mysql概要(十五)存储过程

原文:http://www.cnblogs.com/straybirds/p/5137936.html

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