存储过程中的变量
作者:互联网
变量必须先声明,后使用,一个declare只能申明一个变量
变量赋值有两种方式1.set 2.select into
delimiter $$
CREATE PROCEDURE procedureUseVariable ( )
BEGIN
DECLARE myname VARCHAR(20) DEFAULT '';
set myname='想查出的名字';
select pname into myname from person where pid=2;
select myname;
END;
$$
delimiter ;
call procedureUseVariable();
如果最后想输出myname,只需要在代码块中select myname;即可
举个栗子,想要把学生数和人数放在两个变量中
delimiter $$
create procedure procedureCountGroup()
begin
declare scount int default 0;
declare pcount int default 0;
select count(*) into scount from student;
select count(*) into pcount from person;
select scount,pcount;
end;
$$
结果如下
标签:存储,变量,into,myname,pcount,scount,过程,select 来源: https://www.cnblogs.com/liuyongbo/p/11002704.html