首页 / MYSQL / [MySQL]存储过程
[MySQL]存储过程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[MySQL]存储过程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1991字,纯文字阅读大概需要3分钟。
内容图文
![[MySQL]存储过程](/upload/InfoBanner/zyjiaocheng/500/3e1f981441d94daa802dcf15ee1d0175.jpg)
存储过程语法:
create procedure procedureName
begin
sql 1
end$
显示所有的存储过程 show procedure status;
调用存储过程 call procedureName();
包含if语句的存过:
create procedure procedureName()
begin
declare yy int
if
sql1
else
sql2
end if;
end$
案例:
create procedure procedureName(width int,height int)
begin
select concat(‘你的面积是‘,width*height) as area;
if width >height then
select ‘你挺胖‘;
elseif width <height then
select ‘你挺瘦‘;
else
select ‘你挺方‘;
end if;
end$
编程三步骤
顺序 选择 循环
while循环语句的存过:
求1到100的和;
delimiter $
create procedure procedurename ()
begin
declare total int default 0;
declare num2 int default 0;
while num2<=100 do
set total:=total+num2;
set num2:=num2+1;
end while;
select total;
end$
in/out/inout
--in传入参数
create procedure name (in num int)
begin
declare total int default 0;
declare num2 int default 0;
while num2<=num do
set total:=total+num2;
set num2:=num2+1;
end while;
select total;
end$
--in/out
delimiter$
create procedure p8 (in num int,out total int )
begin
declare num2 int default 0;
set total :=0;
while num2<=num do
set total:=total+num2;
set num2:=num2+1;
end while;
select total;
end$
调用方法:
call p8(100,@tt)
select @tt
--inout
delimiter$
create procedure p9(inout age int)
begin
set age :=age+20;
end$
调用方法:
set @currentage=18
call p9(@currentage)
select @currentage
--case
delimiter$
create procedure p10()
begin
declare pos int default 0;
set pos:=floor(4*rand());
case pos
when 1 then select ‘happy‘;
when 2 then select ‘cry‘;
when 3 then select ‘angry‘;
else select ‘none‘;
end case;
end$
--repeat循环
delimiter$
create procedure p11()
begin
declare total int default 0;
declare i int default 0;
repeat
set i:=i+1;
set total :=total+i;
until i>=100 end repeat;
select total;
end$
[MySQL]存储过程
标签:procedure concat case cat repeat else mys bsp color
本文系统来源:https://www.cnblogs.com/kingwwz/p/8493397.html
内容总结
以上是互联网集市为您收集整理的[MySQL]存储过程全部内容,希望文章能够帮你解决[MySQL]存储过程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。