【发布时间】:2019-07-01 09:10:12
【问题描述】:
我有一个像这样的存储过程sn-p
CREATE DEFINER=`root`@`%` PROCEDURE `new_procedure`()
BEGIN
DECLARE c_id varchar(100) DEFAULT "";
DECLARE cursor1 CURSOR for select id from t1 where name like 's%';
OPEN cursor1;
get_t1: LOOP
FETCH cursor1 into c_id;
p:begin
declare cursor2 cursor for select id from t2 where cl_id=c_id;
open cursor2;
get_t2: loop
fetch project_cursor into p_id;
// perform some tasks
t:begin
declare cursor3 cursor for select id from t3 where pr_id=p_id;
open cursor3;
get_t3:loop
fetch cursor3 into t_id;
IF v_finished = 1 THEN
LEAVE get_t3;
END IF;
//perform some tasks
close cursor3;
select p_id;
end t;
end loop t2;
end p;
END LOOP t1;
END
这里的select语句没有显示任何数据
当我在光标 3 下写选择时,它正在工作。
我做错了吗?我错过了什么
【问题讨论】:
-
“我错过的任何东西” 是的,你错过了一些东西,使用连接会更容易..而且很可能还会提高性能..
-
但我只需要使用存储过程
-
让我知道为什么选择 p_id 没有显示数据
-
"但我只需要使用存储过程"连接也适用于存储过程
-
offtopic:通常也不建议将 root 帐户用作
DEFINER用于存储过程......或者在需要运行生命时用于 anny 查询......
标签: mysql stored-procedures cursor