mysql 存储过程


mysql 存储过程

 

***************************

存储过程

 

创建存储过程

create procedure procedure_name (参数体)
begin
  。。。
end

参数体格式:in | out | inout param_name type,参数体可为空

in:输入参数

out:输出参数

inout:输入输出参数

 

调用存储过程:call procedure_name(param1,param2,...)

查看所有存储过程:show procedure status

查看指定存储过程:show procedure status like ‘%...%’

删除存储过程:drop procedure procedure_name、drop procedure if exists procedure_name

 

 

***************************

流程控制语句

 

if 语句:判断语句

if condition then statement
  elseif condition then statement;
  else statement
end if

 

case 语句:多值判断语句

case expression
  when value1 then statement;
  when value2 then statement;
  ....
  else statement;
end case;

 

loop 语句:循环语句

[loop_label:] loop
  statement;
end loop [loop_label]

 

repeat 语句:循环语句

[repeat_label:] repeat
  statement
until condition
end repeat [repeat_label]

 

while 语句:循环语句

[while_label:] while condition do
  statement
end while [while_label]

 

leave 语句:退出循环标志,语法格式:leave label

iterate 语句:跳转到循环体开始处,语法格式:iterate label

 

 

***************************

示例

 

******************

示例 1

 

drop procedure if exists hh;

delimiter //
create procedure hh()
begin
  select * from test1;
end //
delimiter ;

call hh();

 

操作结果:

      

 

******************

示例 2

 

drop procedure if exists hh;

delimiter //
create procedure hh()
begin
 declare num int default 0;
 select num;
 
 while num<10 do
   set num=num+1;
 end while;
 
 select num;
end //
delimiter ;

call hh();

 

操作结果 1:num 0

操作结果 2:num 10

 

 

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值