mysql存储过程简单案例
管理员 发布于 7年前   380
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();
结果:
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
该博客于2020-12-7日,后端基于go语言的beego框架开发
前端页面使用Bootstrap可视化布局系统自动生成
是我仿的原来我的TP5框架写的博客,比较粗糙,底下是入口
侯体宗的博客
文章标签
友情链接