0
我想在使用遊標和執行的MySQL中創建一個過程。我想反思架構並更新所有具有版本列的表,將版本設置爲0.我認爲我錯過了一個循環(在此尋找幫助),但是我的動態SQL也出現錯誤。有任何想法嗎?MySQL光標和準備聲明 - 什麼是錯誤
DELIMITER $$
CREATE PROCEDURE update_version_number(schemaName int)
BEGIN
DECLARE the_table_name VARCHAR(200);
DECLARE version_cursor CURSOR
FOR
SELECT TABLE_NAME FROM information_schema.columns WHERE table_schema = "myschema" AND COLUMN_NAME = "version" AND TABLE_NAME <> "db_info";
OPEN version_cursor;
FETCH version_cursor into the_table_name;
PREPARE run_version_update From 'UPDATE ? SET version = 0';
SET @a = the_table_name;
EXECUTE run_version_update USING @a;
DEALLOCATE PREPARE run_version_update;
CLOSE version_cursor;
END