mysql> select * from S_TABLE;
+--------+--------------------+
| S_ID | S_TITLE |
+--------+--------------------+
| 1 | Jim |
| 2 | George |
| 3 | Sam |
| 4 | Zoe |
+--------+--------------------+
mysql> select * from F_TABLE;
+--------+--------+--------------+----------+
| F_ID | S_ID | F_VALUE | F_TITLE |
+--------+--------+--------------+----------+
| 1 | 1 | 4.5 | Delta |
| 2 | 2 | 24.5 | Gamma |
| 3 | 3 | 44.4 | RHO |
| 4 | 3 | 5.0 | Beta |
+--------+--------+--------------+----------+
mysql> select * from Results; // Hence this table is empty
+--------+-------------+
| Fstuff | Sstuff |
+--------+-------------+
| | |
+--------+-------------+
This stored procedure does a frivolous computation
DELIMITER ##
CREATE PROCEDURE zap(IN sss VARCHAR(30))
BEGIN
INSERT INTO Results (fstuff, Sstuff)
Select
f.F_VALUE * 0 + 123,
s.S_TITLE
FROM F_TABLE f
JOIN S_TABLE s ON s.S_ID=f.S_ID
WHERE s.S_TITLE LIKE CONCAT('%', sss, '%');
END ##
DELIMITER ;
This stored procedure calls zap
DELIMITER ##
CREATE PROCEDURE crap()
BEGIN
DECLARE fTit VARCHAR(30);
DECLARE done INT DEFAULT 0;
DECLARE cur CURSOR FOR SELECT F_TITLE FROM F_TABLE;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
read_loop: LOOP
FETCH cur INTO fTit;
IF done
THEN LEAVE read_loop;
END IF;
call Zap(fTit);
COMMIT;
END LOOP;
CLOSE cur;
END ##
DELIMITER ;
Problem: Result table becomes uneffected? I cant figure out why
You read out the names from
F_TABLE.F_TITLE(Delta,Gamma…) and look for them inS_TABLE.S_TITLEand there is no match.The cursor in
crapshould use the same title column as thezapprocedure.edit:
The cursor
cur CURSOR FOR SELECT F_TITLE FROM F_TABLE;will fetch ‘Delta’,’Gamma’ and so on intofTit. ThenZap()is called:Zap('Delta'),Zap('Gamma')etc.The
Zapprocedure will create a match string'%Delta%','%Gamma%'and so on and look for this in the first table you listed. Since that table contains ‘Jim’, ‘George’ and other names there is no match. TheSELECTreturns no rows so there is nothing inserted in any of the calls tozap.If you change the cursor to instead look in
S_TABLEyou will get rows inserted, but maybe not the ones you want. Please explain more what you expect in the results table.