Hi,
I need something like ‘for each record null in table A’, update table A where the condition, using MySql 5.5.46.
My first approach was create a SP with this lines
CREATE DEFINER=`tUser`@`%` PROCEDURE `ROW_PER_ROW`()
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
DECLARE tYear INT(4);
SET tYear = YEAR(CURDATE());
SET GLOBAL innodb_lock_wait_timeout = 50000;
SET innodb_lock_wait_timeout = 50000;
SET @s = CONCAT('SELECT COUNT(*) FROM `tbl_A_',tYear,'_new`
WHERE tType IS NULL INTO @n;');
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT @n;
SET i=0;
WHILE i<@n DO
SELECT i;
SET @s = CONCAT('UPDATE `tbl_A_',tYear,'_new`
SET tType = ''IB''
WHERE
tDecription IN (''SGA'')
AND tType IS NULL
LIMIT i, 1;');
SELECT @s;
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET i = i + 1;
SELECT i;
END WHILE;
END
The value of @n
it’s 169150
(correctly).
The error is
Procedure execution failed 1327 - Undeclared variable: i Time: 0,459s
Help me to do it…