2
我想要處理表「accounts」的所有列名稱。 我發現這個存儲過程堆棧溢出,但它不按預期工作。光標未打開錯誤
delimiter $
create procedure prc_column()
BEGIN
DECLARE num_rows int;
declare i int;
declare col_name varchar(1000);
DECLARE col_names CURSOR FOR
SELECT column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'accounts'
ORDER BY ordinal_position;
select FOUND_ROWS() into num_rows;
SET i = 1;
the_loop: LOOP
IF i > num_rows THEN
CLOSE col_names;
LEAVE the_loop;
END IF;
FETCH col_names
INTO col_name;
// do something with column names for e.g. append it with _drupal
SET i = i + 1;
END LOOP the_loop;
END
我得到一個錯誤:
ERROR 1326(24000):遊標未打開
之前聲明打開的遊標是否有可能將表名稱提供給像prc_column(帳戶)這樣的過程? – shantanuo 2011-02-10 11:14:06