我正在尝试通过存储过程从数据库中获取记录,但出现了
错误
“命令不同步现在无法运行”
这是我的存储过程代码。任何哥们都可以帮助我,我浪费了太多时间
DELIMITER $$
create procedure get_industrialchildIDs(in id int)
BEGIN
DECLARE total_rows int;
SET total_rows=0;
create TEMPORARY table IF NOT EXISTS temp_table1(CategoryChildId int(11));
truncate table temp_table1;
insert into temp_table1 SELECT CategoryChildId FROM tblcategoryparentchildassociations WHERE CategoryParentId=id;
SELECT count(CategoryChildId) into total_rows from temp_table1;
create TEMPORARY table IF NOT EXISTS temp_table (CategoryChildId int(11));
truncate table temp_table;
create TEMPORARY table IF NOT EXISTS temp_table2(CategoryChildId int(11));
insert into temp_table select id from tblmastercategories where id in (select CategoryChildId from tblcategoryparentchildassociations where CategoryParentId = id) AND flag_Industr_sub = 1;
WHILE total_rows <> 0 DO
insert into temp_table select id from tblmastercategories where id in (select CategoryChildId from tblcategoryparentchildassociations where CategoryParentId in (SELECT CategoryChildId FROM temp_table1)) AND flag_Industr_sub = 1;
delete from temp_table2 where 1=1;
insert into temp_table2 SELECT CategoryChildId FROM temp_table1;
delete from temp_table1 where 1=1;
insert into temp_table1 select CategoryChildId from tblcategoryparentchildassociations where CategoryParentId in (SELECT CategoryChildId FROM temp_table2);
SELECT count(CategoryChildId) into total_rows from temp_table1;
END WHILE;
SELECT CategoryChildId FROM temp_table;
END $$
DELIMITER ;