添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
drop table if exists test_tbl;
create table test_tbl (name varchar(20), status int(2));
insert into test_tbl values('abc', 1),('edf', 2),('xyz', 3);
drop procedure IF EXISTS pro_test_3;
delimiter //
create procedure pro_test_3()
begin
--  方式 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;
delimiter ;
call pro_test_3();
drop table if exists test_tbl;create table test_tbl (name varchar(20), status int(2));insert into test_tbl values('abc', 1),('edf', 2),('xyz', 3);drop procedure IF EXISTS pro_test_3;delimiter //
一、 变量 的定义 mysql 变量 定义用declare来定义一局部 变量 ,该 变量 的使用范围只能在begin…end 块中使用, 变量 必须定义在复合语句的开头,并且是在其它语句之前,也可以同时申明多个 变量 ,如果需要,可以使用default赋默认值。 定义一个 变量 语法如下: declare var_name[,…] type[default value]看一个 变量 定义实例 declare last date;二、 mysql 存储过程 变量 赋值 变量 赋值 可直接 赋值 查询 赋值 来操作,直接 赋值 可以用set来操作,可以是常量或表达式如果下 代码如下: set var_name= [,var_name expr]
Mysql 存储过程 查询 结果 赋值 变量 方法 转载: [ Mysql 存储过程 查询 结果 赋值 变量 方法 ](https://www.cnblogs.com/mytzq/p/7090197.html). 转载: Mysql 存储过程 查询 结果 赋值 变量 方法 . drop table if exists test_tbl; create table test_tbl (name varchar(20), status int(2)); insert into test_tbl values('abc', 1),('edf',