Mysql存储过程查询结果赋值到变量的方法
01
drop table if exists test_tbl;
02
create table test_tbl (name varchar(20), status int(2));
03
insert into test_tbl values('abc', 1),('edf', 2),('xyz', 3);
04 05
drop procedure IF EXISTS pro_test_3;
06
delimiter //
07
create procedure pro_test_3()
08
begin
09
-- 方式 1
10
DECLARE cnt INT DEFAULT 0;
11
select count(*) into cnt from test_tbl;
12
select cnt;
13 14
-- 方式 2
15
set @cnt = (select count(*) from test_tbl);
16
select @cnt;
17 18
-- 方式 3
19
select count(*) into @cnt1 from test_tbl;
20
select @cnt1;
21 22
-- 多个列的情况下似乎只能用 into 方式
23
select max(status), avg(status) into @max, @avg from test_tbl;
24
select @max, @avg;
25
end
26
//
27
delimiter ;
28 29
call pro_test_3();
Mysql存储过程查询结果赋值到变量的方法的更多相关文章
- Mysql 存储过程查询结果赋值到变量的方法
drop table if exists test_tbl; create table test_tbl (name varchar(20), status int(2)); insert into ...
- Mysql存储过程查询结果赋值到变量
# 使用的navicat 编辑的存储过程 CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_student_back`()BEGIN#定义max ...
- mysql存储过程查询结果循环遍历 判断 赋值 游标等基本操作
一.首先说下本篇博客所实现功能的背景和功能是怎样的: 背景:因为公司项目开始迁移新平台项目,所以以前的平台老数据以及订单信息需要拆分表,而且需要业务逻辑来分析以前的订单表,来拆分成另外的几个新表,包括 ...
- php将SQL查询结果赋值给变量
2012-03-25 12:12 a786013819 | 分类:数据库DB | 浏览1393次 $sql = "select field1 from pre_common_member_p ...
- mysql 存储过程查询语句
可以用 命令"show PROCEDURE status"查看所有的存储过程或检索系统表"mysql.proc"来查询已有的存储过程.例如:用show PROC ...
- 在Excel VBA中将SQL查询的结果赋值给变量的方法
直接上代码示例: nowdate为日期型变量 strSql = "select DISTINCT 日期 from new_ubi_data ORDER BY 日期 DESC Limit 0, ...
- MySQL存储过程中一直困扰的 の 变量中的@
在声明变量中CREATE function Get_StrArrayLength ( @str varchar(1024), --要分割的字符串@split varchar(10) --分隔符号)re ...
- mysql存储过程(查询数据库内表 游标循环 if判断 插入别的表内)
BEGIN declare f_age int;DECLARE incode1 VARCHAR(100);DECLARE incode2 VARCHAR(100);DECLARE incode3 VA ...
- mysql查看表的属性 mysql将查询结果给临时变量
查看所有的表show table status ; 查看具体的某张表show table status from xxdb like 'tm_properties' ; 查看具体的字段的意思 sele ...
随机推荐
- 安装Visual Studio 2013 出现0x80070643错误
安装Visual Studio 2013 没一会就出现问题:安装.net framework4.5.1出现严重错误.点击常见问题和解决方案的链接和日志文件,日志里说是0x80070643类型的错误,在 ...
- 用 perl 统计 fasta 文件序列的总长
#!/usr/bin/perl -w use strict; die "Usage: $0 <file>\n" unless (@ARGV == 1); my $lin ...
- 【BZOJ-4199】品酒大会 后缀数组 + 并查集合并集合
4199: [Noi2015]品酒大会 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 436 Solved: 243[Submit][Status] ...
- 【bzoj2242】 SDOI2011—计算器
http://www.lydsy.com/JudgeOnline/problem.php?id=2242 (题目链接) 题意 给出y,z,p.求:1.yz mod p:2.xy=z(mod p):3. ...
- Linux列出安装过的程序
命令行: dpkg -l apt-cache(模糊搜索apt-cache search 包名) pkgnames yum list(ubuntu下试了无效) rpm -aq(ubuntu下试了无效)
- QCustomPlot 使用整理
QCustomPlot 是一个比较小的 QT 图表插件.使用时,我们在程序中写完相关调用的代码后,只需将 QCunstomPlot.cpp 和 QCustomPlot.h 两个文件加入工程,正常编译即 ...
- PriorityQueue
基本概念 顾名思义,PriorityQueue是优先级队列,它首先实现了队列接口(Queue),与LinkedList类似,它的队列长度也没有限制,与一般队列的区别是,它有优先级的概念,每个元素都有优 ...
- POJ 1236 Network of Schools(强连通分量/Tarjan缩点)
传送门 Description A number of schools are connected to a computer network. Agreements have been develo ...
- 使用substring方法进行字符串拆分
对一个字符串进行操作,我们通常会用到这2个类:String类.StringBuffer类 而这2个类中的方法大多都是相同的,今天主要介绍他俩共同的一个特别有用的方法:substring substri ...
- React Native 开发之 (06) JSX
一 React 1 React定义 React的GitHub地址是 https://github.com/facebook/react.它的官方介绍是 A JavaScript Library for ...