共計 934 個字符,預計需要花費 3 分鐘才能閱讀完成。
自動寫代碼機器人,免費開通
本篇內容主要講解“MySQL 游標的嵌套使用方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓丸趣 TV 小編來帶大家學習“MySQL 游標的嵌套使用方法”吧!
前幾天群里有人問 MySQL 的游標能不能嵌套使用,想當然地以為不能,后來試了下,居然可以,唉,不能隨便想當然啊。例子如下:
CREATE PROCEDURE curdemo()
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT
BEGIN
declare done1,done2 int default 0;
declare name1,name2 varchar(20);
declare id1,id2 int;
declare cur1 cursor for select id,name from test1;
declare continue handler for not found set done1 = 1;
open cur1;
repeat
fetch cur1 into id1, name1;
if not done1 then
insert into test3(name) values(name1);
begin
declare cur2 cursor for select id,name from test2;
declare continue handler for not found set done2 = 1;
open cur2;
repeat
fetch cur2 into id2,name2;
if not done2 then
insert into test3(name) values(name2);
end if;
until done2 end repeat;
close cur2;
set done2=0;
end;
end if;
until done1 end repeat;
close cur1;
commit;
END;
到此,相信大家對“MySQL 游標的嵌套使用方法”有了更深的了解,不妨來實際操作一番吧!這里是丸趣 TV 網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
向 AI 問一下細節