注意同全局变量和用户变量区分开。
使用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 tableSELECT 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;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)