mysql存储过程简单案例
数据库  /  管理员 发布于 5年前   551
1.多字段
CREATE DEFINER=`root`@`localhost` PROCEDURE `r404`(a int)
begin
select * from cunzhu ;
SET @count = (select count(*) from cunzhu);
select @count;
select count(*),name,age,home into @count,@name,@age,@home from cunzhu where id=a;
select @count,@name,@age,@home;
end;
call r404(2);
结果:
2.循环查询
CREATE DEFINER=`root`@`localhost` PROCEDURE `r405`()
begin
declare i int default 1;
loop_label: loop
select * from cunzhu where id=i;
set i=i+1;
if i>3 then
leave loop_label;
end if;
end loop;
end;
call r405();
结果:
3.动态拼接
CREATE DEFINER=`root`@`localhost` PROCEDURE `r408`()
begin
set @aa = 'select name from cunzhu where id=2';
set @sentence = concat(@aa);
prepare aa from @sentence;
execute aa;
deallocate prepare aa;
end;
call r408();
结果:
博主 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..xiaoB 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..BUG4 在
你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..博主 在
go语言+beego框架中获取get,post请求的所有参数中评论 @ t1 直接在router.go文件中配就ok..Jade 在
如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号