码迷,mamicode.com
首页 > 数据库 > 详细

MySQL创建存储过程

时间:2017-09-10 01:06:06      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:bsp   sql   blog   log   com   end   begin   logs   html   

存储过程和函数的区别参考链接:

http://www.cnblogs.com/lengbingshy/archive/2010/02/25/1673476.html

创建存储过程:

DROP PROCEDURE mypro;
CREATE procedure mypro (sid INT,OUT sCount INT)
BEGIN

SELECT COUNT(*) INTO sCount from student where id = sid;
END

执行该存储过程:

CALL mypro(1,@c);
select @c;

创建函数:

DROP FUNCTION myfun;
CREATE FUNCTION myfun (sid INT)
RETURNS int
BEGIN
DECLARE sCount int;
SELECT COUNT(*) INTO sCount from student where id=sid;
RETURN sCount;
END

执行函数:
SELECT myfun(1)

MySQL创建存储过程

标签:bsp   sql   blog   log   com   end   begin   logs   html   

原文地址:http://www.cnblogs.com/wanjn/p/7499842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!