mysql存储过程详细注释
delimiter $$ /* 重新定义mysql结束符,⽽不再是分号是结束符 */
create procedure mergeDeclare() /* 创建存储过程 */
BEGIN
/*定义局部变量*/
经营理念DECLARE id INT DEFAULT 0;
DECLARE Done INT DEFAULT 0;
DECLARE mobile VARCHAR(20);
DECLARE mobileTemp VARCHAR(20) DEFAULT '';
DECLARE maxId INT DEFAULT 0;
DECLARE t_error INTEGER DEFAULT 0;
DECLARE rs CURSOR FOR /* 定义从mysql取数据的游标 */
/* 查出需要的数据 */
lect
a.declare_id,a.ur_mobile
from
declare_info a,
(lect ur_mobile from declare_info b where b.status=1 group by ur_mobile having count(1)>1) b
我是你的谁歌词
where
a.ur_mobile=
b.ur_mobile and a.status =1 and CHARACTER_LENGTH(a.ur_mobile) = 11 ORDER BY a.ur_mobile , a.declare_id DESC;
/* 当游标遍历完所有数据的时候,t Done的值为1 */
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;
/* 当发⽣sql异常的时候t t_error的值为1 */
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1;
/* 开启事务 */
START TRANSACTION;
/* 打开游标 */
OPEN rs;
电脑操作手机/* 取游标当前的值,into后⾯是赋值的意思,被赋值变量的数⽬与sql查出来的字段数相等 */描写春天的优美短句
FETCH NEXT FROM rs INTO id,mobile;女神生日蛋糕图片
/* 在此处进⾏循环 */
REPEAT
IF NOT Done THEN
IF mobileTemp = mobile THEN
UPDATE farmer_certification_info t declare_id = maxId where declare_id = id;
UPDATE farmer_contact_info t declare_id = maxId where declare_id = id;
UPDATE farmer_industry_info t declare_id = maxId where declare_id = id;
UPDATE farmer_info t declare_id = maxId where declare_id = id;
UPDATE farmer_job_info t declare_id = maxId where declare_id = id;
UPDATE farmer_skill_info t declare_id = maxId where declare_id = id;
UPDATE training_class_ur t declare_id = maxId where declare_id = id;
UPDATE training_class_evaluate t declare_id = maxId where declare_id = id;
UPDATE declare_info t `status`= 0 where declare_id = id;
ELSE
简历表t mobileTemp = mobile;
t maxId = id;
END IF;
END IF;
IF t_error = 1 THEN
/* sql异常回滚 */
ROLLBACK;
ELSE
/* 提交事务 */
COMMIT;
END IF;
/* 向游标取出下⼀个值进⾏赋值 */
FETCH NEXT FROM rs INTO id,mobile;
/* 遍历完Done=1,结束遍历 */
UNTIL Done END REPEAT;
/*关闭游标*/
CLOSE rs;
END $$ /* 结束符,和开始定义的⼀致 */
/*
drop procedure mergeDeclare /* 删除存储过程 */拟人句的意思
*/
/*
call mergeDeclare() /* 调⽤存储过程 */
*/
第二次世界大战转折点标注:存储过程没有容器和数据概念,但可新建表借助表当作⼀个容器使⽤。