博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mysql存储过程查询结果赋值到变量
阅读量:4652 次
发布时间:2019-06-09

本文共 774 字,大约阅读时间需要 2 分钟。

# 使用的navicat  编辑的存储过程

CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_student_back`()

BEGIN
#定义max变量
DECLARE max INT DEFAULT 0;
select max(id) into max from student_back;
#判断是不是空值 是空值就赋值为0
if max is null then
  set max = 0;
end if;

#备份数据

INSERT INTO student_back () SELECT * from student where id > max limit 10;

select max(id) into max from student_register_back;

#返回值

select max;

END
#结束
其他方法:

-- 方式 1

DECLARE cnt INT DEFAULT 0;
select count(*) into cnt from test_tbl;
select cnt;
-- 方式 2
set @cnt = (select count(*) from test_tbl);
select @cnt;

 

-- 方式 3

select count(*) into @cnt1 from test_tbl;
select @cnt1;

 

-- 多个列的情况下似乎只能用 into 方式

select max(status), avg(status) into @max, @avg from test_tbl;

select @max, @avg;

转载于:https://www.cnblogs.com/code-bugs/p/10286589.html

你可能感兴趣的文章
CentOS安装python-2.7+安装pip-10.0.0
查看>>
串行通信概念解析
查看>>
Sublime text 2之WIN7下安装Zencoding插件和使用
查看>>
python玩丢手绢问题,出局的顺序
查看>>
ASP:Checkbox验证非空的一种方法
查看>>
[CQOI2013]新Nim游戏 线性基
查看>>
我的成就故事
查看>>
electron-vue 更新 使用electron-update的版本
查看>>
设计模式_责任链模式
查看>>
HTTP请求中三种参数类型
查看>>
3DES加密/解密
查看>>
【转】C#常用控件名缩写-C#_ControlName
查看>>
CF990G
查看>>
四则运算(2.0)
查看>>
进度条
查看>>
Noip2013货车运输
查看>>
vmware安装minimal centos报错/etc/rc5.d/s99local : line:25 : eject : command not found
查看>>
邮件模板定义
查看>>
odoo server命令行以及配置文件
查看>>
16 On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima 1609.04836v1
查看>>