简体   繁体   中英

Stored iterative procedure not inserting into table

I'm utilizing two procedures, one to define a cursor and the second to insert the results of the first into a temporary table before inserting into the final table. I have tested my select query definition for the cursor and it is returning the results I would like; however, I am getting no values inserted into my temporary table.

Iterative Procedure

CREATE PROCEDURE procIteration ()
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE TaxonName varchar(170);
DECLARE RankID varchar(170);
DECLARE ParentID varchar(170);
DECLARE TaxonID varchar(170);
DECLARE cur CURSOR FOR SELECT child.SciName, RankID, parent.parentID, child.tid FROM taxa child LEFT JOIN (SELECT MAX(parenttid) as parentID, SciName, taxaenumtree.tid FROM taxaenumtree, taxa WHERE taxa.tid = taxaenumtree.tid GROUP BY taxaenumtree.tid) AS parent ON parent.tid = child.tid WHERE rankID = 10;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;

OPEN cur;

testLoop: LOOP
    FETCH cur INTO TaxonName, RankID, ParentID, TaxonID;
    IF done THEN 
        LEAVE testLoop;
    END IF;
    CALL taxon_reclamation(TaxonName, RankID, ParentID, TaxonID);
END LOOP testLoop;

CLOSE cur;
END //

Inserting Procedure

CREATE PROCEDURE taxon_reclamation (IN TaxonNameIn VARCHAR(170), IN RankIDIn VARCHAR(170), IN ParentIDIn VARCHAR(11), IN TaxonIDIn VARCHAR(170)) 
BEGIN
DECLARE TaxonName varchar(170);
DECLARE RankID varchar(170);
DECLARE ParentID varchar(170); 
DECLARE TaxonID varchar(170);
SET TaxonName = TaxonNameIn;
SET RankID = RankIDIn;
SET TaxonID = TaxonIDIn;
SET ParentID = ParentIDIn;

INSERT INTO taxon_reclamation(TaxonID, FullName, Name, RankID, ParentID, TaxonTreeDefID, TaxonTreeDefItemID)
VALUES (TaxonID, TaxonName, TaxonName, RankID, ParentID, 2, 1);
END //

I should be getting a temporary table with the name of the taxon, the taxon ID, the parent ID for that taxon and its rankID (family, genus, species, etc).

您应该更改变量名,以便它们与列名不同。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM