【MySQL】存储过程、游标、循环简单实例
时间:2021-07-01 10:21:17
帮助过:53人阅读
- create procedure my_procedure()
- begin
- declare my_id varchar(32);
- declare my_name varchar(50);
- DECLARE done INT DEFAULT FALSE;
-
- DECLARE My_Cursor CURSOR FOR ( SELECT id, name FROM t_people );
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- OPEN My_Cursor;
- myLoop: LOOP
- FETCH My_Cursor into my_id, my_name;
- IF done THEN
- LEAVE myLoop;
- END IF;
-
- UPDATE t_user SET c_name = my_name WHERE id = my_id and rtrim(ltrim(c_name)) = ‘‘;
-
- COMMIT;
- END LOOP myLoop;
- CLOSE My_Cursor;
- END;
sql 调用存储过程
[sql] view plain
copy
- call my_procedure();
sql 删除存储过程
[sql] view plain
copy
- drop procedure my_procedure;
End .
【MySQL】存储过程、游标、循环简单实例
标签:-- 存储过程 判断 log 通过 pop 执行存储过程 tin call