笨笨网美国主机,w ww.2 b p .n e t
mysql存储过程中局部变量定义在代码最前面,作用范围也是在此函数范围内。注意同全局变量和用户变量区分开。
使用declare关键字来声明变量
注意必须写在代码块的最前面
de count int DEFAULT 0;DECLARE username varchar(32);
一次声明多个相同类型的变量
DECLARE p_parent int DEFAULT 0;DECLARE parent0, parent1, parent2, parent3, parent4, parent5 int DEFAULT 0;
使用set来给变量赋值
set <变量名> = <值>
DECLARE sflag int default 0; set sflag =100;
select 语句给变量赋值
select 列名 into 变量名,支持多个变量同时赋值。
SELECT col_name[, …] INTO var_name[,…] from table
SELECT IFNULL(cnt,0) into parent0 from temp_student where b = 0 limit 1;select sname, sno into p_name, p_no from temp_student where id=888;select 'result:', p_no, p_name;
游标赋值
DECLARE p_id int;DECLARE p_name varchar(32);DECLARE sflag int DEFAULT 0;DECLARE cur_school CURSOR FOR select id,name from school where status=0;DECLARE CONTINUE HANDLER FOR NOT FOUND SET sflag = 1;open cur_school;fetch cur_school into p_id, p_name; while sflag<>1 do // ...... fetch cur_school into p_id, p_name; select 'in while:',p_id, sflag;end while;close cur_school;
笨笨网美国主机,w ww.2 b p .n e t
提醒:《mysql存储过程和函数区别(附举例详细mysql存储过程)》最后刷新时间 2025-03-21 11:13:52,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《mysql存储过程和函数区别(附举例详细mysql存储过程)》该内容的真实性请自行鉴别。