如何使用從Cursor返回的值作爲mysql過程中的表名?傳遞表名以從光標選擇語句
DECLARE cur CURSOR FOR
select table_name, column_name
from information_schema.columns
where table_schema = 'foo' and table_name like 'bar%';
OPEN cur;
loop1: LOOP
FETCH cur
INTO table_val, column_val;
IF no_more_rows THEN
CLOSE cur;
LEAVE loop1;
END IF;
update table_val SET column_val ...
這會引發錯誤foo.table_val doesnt exist
。我如何才能將實際的表名傳遞給select語句?
要爲表使用動態名稱,您必須使用準備語句(動態sql)。你知道嗎? – Sami