mysql存储过程和函数区别(附举例详细mysql存储过程)

   发布日期:2025-07-04 04:20:05     手机:https://m.qqhuangye.com/zhishi/1777.html     违规举报

mysql存储过程和函数区别(附举例详细mysql存储过程)

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;
 
 
本文地址:https://www.qqhuangye.com/zhishi/1777.html,转载请注明出处。"error":400,"message":"over quota","url:"https://www.qqhuangye.com/zhishi/1777.html
 
更多>同类知识

推荐图文
推荐知识
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  违规举报  |  蜀ICP备18010318号-2  |  SiteMaps  |  BaiDuNews
Processed in 0.293 second(s), 8 queries, Memory 0.52 M