mysql存储过程

简单的存储过程:

DROP PROCEDURE IF EXISTS `proc_adder`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_adder`(IN a int, IN b int, OUT sum int)
BEGIN

    DECLARE c int;
    if a is null then set a = 0; 
    end if;
  
    if b is null then set b = 0;
    end if;
set sum  = a + b;
END
;;
DELIMITER ;

IN a int, IN b int, OUT sum int

a,b 为输入参数;sum是输出参数

 

可以像上图一样调用,并且获取输出参数

 

存储过程 if  case  WHILE  

   参照:https://blog.csdn.net/xiaolyuh123/article/details/76147102

https://yq.aliyun.com/articles/112753

游标在存储过程中的使用

create procedure t()
begin
     declare done boolean DEFAULT true;

     declare id int(11);

     declare tdate datetime;

     declare cur CURSOR for select * from student;



     declare continue handler for not found set done = false;
     -- 若临时表已存在先删除
     drop temporary table if exists ss;

     create temporary table ss(
            id int(11),
            date datetime
     );

     open cur;
          while done do
                -- 获取数据
                fetch cur into id,tdate;
                -- TODO 需要执行的操作放在循环中,这里完成插入。
                insert into ss value(id,tdate);

          end while;
     close cur;

     -- 返回统计的记录
     select * from ss;
end;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值