I have a stored procedure in MySQL
CREATE PROCEDURE insertFromJunction ()
BEGIN
DECLARE iteration INT DEFAULT NULL;
DECLARE adjacentID INT DEFAULT 0;
DECLARE junction VARCHAR(20) DEFAULT 0;
SET junction = 'H';
SET iteration = 1;
loop2: LOOP
SET adjacentID = (SELECT junction FROM Hybrid WHERE Hybrid_ID = iteration);
IF iteration = 2 THEN LEAVE loop2; --it can even be 1,3 etc
END IF;
SET iteration = iteration + 1;
END LOOP loop2;
END;
$$
Now here is the hybrid table
Hybrid_ID N K J H
1 15 10 11 9
2 13 15 5 7
3 20 16 4 10
4 NULL NULL 3 NULL
5 NULL NULL 2 NULL
6 NULL NULL NULL NULL
So, basically what should happen is that the loop runs first time adjacenID = 9
, then iteration = 1+1=2
.
Then loop runs second time adjacentID = 7
and loop should terminate (from IF). But there is an error and it is when the SET
staement is executing.
Error Code: 1366. Incorrect integer value: 'H' for column 'adjacentID' at row 2
What is being done wrong. I checked all the data types too.
The error persists even when termination condition is set to iteration = 1
which make me suspicious because there is no point of row 2
in that case.