日期:2014-05-16 浏览次数:20818 次
BEGIN DECLARE p VARCHAR(25); DECLARE pid int; DECLARE c varchar(25); DECLARE cid int; declare ct varchar(25); declare ctid int; declare t varchar(25); declare v varchar(25); DECLARE l_done INT DEFAULT 0; DECLARE cu_p CURSOR FOR SELECT Name FROM province; DECLARE cu_c CURSOR FOR SELECT Name FROM city ProvinceID = pid;#这个where条件是根据上一轮的PID来进行查询的,但是好像嵌套的时候无法这样使用. DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_done=1; OPEN cu_p; cu_p_loop: LOOP FETCH cu_p INTO p; insert into china(`name`,`parentid`) values (p,1); select LAST_INSERT_ID() INTO pid; #我要怎么才能把这个自增ID放到下一个游标循环中使用 OPEN cu_c; cu_c_loop:LOOP FETCH cu_c into c; #插入市级 INSERT into china(`name`,parentid) values(c,pid); end loop; CLOSE cu_c; end loop; CLOSE cu_p; END