I am working on a stored procedure and I have a rather complicated set of instructions in this query. (I apologize for the odd variable names, I had to mask data)
I have delcared a variable varId
and am using a cursor to assign that value during a loop (curseLoop
). I have created a second cursor where I need to use that varId
in a WHERE clause.
When I execute the stored procedure I get Error Code: 1329. No data - zero rows fetched, selected, or processed
.
How do I fix this, or is my procedure structure completely wrong here?
CREATE PROCEDURE `build_roster`(
IN idList VARCHAR(255) -- comma separated string of contract ids
)
BEGIN
DECLARE done INT;
DECLARE doneAgain INT;
-- variable for the first select statement to retrieve the billing id
DECLARE varId INT DEFAULT 0;
-- variable set that will build the roster table based on the billing id
DECLARE var1 VARCHAR(25);
DECLARE var2 VARCHAR(25);
DECLARE var3 DATETIME;
DECLARE var4 DATETIME;
DECLARE var5 DATETIME;
DECLARE var6 INT;
-- buffer for outside loop
DECLARE curse CURSOR FOR
SELECT id from billing_file WHERE FIND_IN_SET(contract_id, contract_id_list);
-- buffer for interior loop
DECLARE secondCurse CURSOR FOR
Select c.col1, c.col2, p.colA, p.colB, p.colC, cl.col from tableC c
INNER JOIN tableP p ON c.col1 = p.colA
INNER JOIN tableCL cl ON c.col2 = cl.col2A
where c.miscCol = varId -- this is where I'm having an issue I think
GROUP BY c.col1, c.col2, p.colA, p.colB
ORDER BY p.colB ASC;
-- set up the temporary table to house all the data that we find through the loops
DROP TEMPORARY TABLE IF EXISTS results;
CREATE TEMPORARY TABLE IF NOT EXISTS results (
var1 VARCHAR(25) NOT NULL,
var2 VARCHAR(25) NOT NULL,
var3 DATETIME NOT NULL,
var4 DATETIME,
var5 DATETIME,
var6 TINYINT(1) DEFAULT 0
);
-- begin parsing the data
OPEN curse;
curseLoop : LOOP
FETCH curse INTO varId;
OPEN secondCurse;
secondCurseLoop : LOOP
FETCH secondCurse INTO var1, var2, var3, var4, var5, var6;
INSERT INTO results VALUES (var1, var2, var3, var4, var5, var6);
END LOOP secondCurseLoop;
CLOSE secondCurse;
END LOOP curseLoop;
CLOSE curse;
-- run a quick select to verify data is pulled, this is the stopping point for this procedure build until I verify it all works
SELECT * FROM results;
END
I ran the procedure as CALL build_roster("14,15");
using MySQL Workbench.
I was expecting an output of rows consisting of var1, var2, var3, var4, var5, var6
. I did not received that data.