問題的基礎上刪除父節點ID子節點:需要使用MySQL存儲過程
我需要刪除基於父節點ID子節點。所以請幫助我。
注:
下面這個存儲過程我選擇基於父節點ID子節點做出。
CREATE DEFINER=`root`@`localhost` PROCEDURE `Hierarchy`(IN `GivenID` INT, IN `initial` INT) BEGIN DECLARE done INT DEFAULT 0; DECLARE next_id INT; -- CURSOR TO LOOP THROUGH RESULTS -- DECLARE cur1 CURSOR FOR SELECT GID FROM civicsoft_group WHERE Parent_Group_ID = GivenID; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; -- CREATE A TEMPORARY TABLE TO HOLD RESULTS -- IF initial=1 THEN -- MAKE SURE TABLE DOESN'T CONTAIN OUTDATED INFO IF IT EXISTS (USUALLY ON ERROR) -- DROP TABLE IF EXISTS OUT_TEMP; CREATE TEMPORARY TABLE OUT_TEMP (TGID int,TParent_Group_ID int, TGroup_Name varchar(32),TGroup_Type varchar(1),TProject_Status tinyint(1),TEID int,TEmp_Group_ID int,TEmp_Name varchar(100),TEmp_Type varchar(2)); END IF; -- ADD OURSELF TO THE TEMPORARY TABLE -- INSERT INTO OUT_TEMP SELECT cg.GID,cg.Parent_Group_ID,cg.Group_Name,cg.Group_Type,cg.Project_Status,ce.EID,ce.Emp_Group_ID,ce.Emp_Name,ce.Emp_Type FROM civicsoft_group cg LEFT JOIN civicsoft_employee ce ON cg.GID = ce.Emp_Group_ID WHERE cg.GID = GivenID; -- AND LOOP THROUGH THE CURSOR -- OPEN cur1; read_loop: LOOP FETCH cur1 INTO next_id; -- NO ROWS FOUND, LEAVE LOOP -- IF done THEN LEAVE read_loop; END IF; -- NEXT ROUND -- SET @@GLOBAL.max_sp_recursion_depth = 255; SET @@session.max_sp_recursion_depth = 255; CALL Hierarchy(next_id, 0); END LOOP; CLOSE cur1; -- THIS IS THE INITIAL CALL, LET'S GET THE RESULTS -- IF initial=1 THEN SELECT * FROM OUT_TEMP; -- CLEAN UP AFTER OURSELVES -- DROP TABLE OUT_TEMP; END IF; END
這是什麼問題? – fancyPants
我想根據父節點ID刪除子節點。我在存儲過程上面做了選擇。但對於刪除,我不知道該怎麼辦。 PLZ幫助我。我是新的MySQL存儲過程 – user2994953
即使我只從互聯網複製此程序。 – user2994953