1
準備好的發言,我把準備好的語句的遊標聲明,然後執行它,然後返回一個error #1324 - Undefined CURSOR: getid.
使用帶有光標
我該如何解決這個問題?
delimiter ;; drop procedure if exists test2;; create procedure test2(table_id VARCHAR(25)) BEGIN DECLARE done INT DEFAULT FALSE; DECLARE id INT; DECLARE id_new INT; DECLARE stmt1 VARCHAR(1024); DECLARE stmt2 VARCHAR(1024); DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; SET @sqltext1 := CONCAT('DECLARE getid CURSOR FOR SELECT entryId FROM ',table_id,' ORDER BY entryId'); PREPARE stmt1 FROM @sqltext1; EXECUTE stmt1; SET @id_new = 1; OPEN getid; FETCH getid into id; REPEAT SET @sqltext2 := CONCAT('UPDATE ',table_id,' SET entryId = ? WHERE entryId = ?'); PREPARE stmt2 FROM @sqltext2; EXECUTE stmt2 USING @new_id, id; SET @id_new = @id_new + 1; FETCH getid into id; UNTIL done END REPEAT; CLOSE getid; END ;; CALL test2('Test');
謝謝。但它返回#1327 - 未聲明的變量:id。我通過phpmyadmin導入它。 – user3274165
我沒有問題來創建過程,但是當我調用它時,它返回#1193 - 未知的系統變量'entryId',我該如何解決它?再次感謝 – user3274165
'set @ sqltext2:= concat('set entryId =?where entryId =?');'是問題所在。固定。更新了我的答案。 –