我希望处理表"帐户"的所有列名称.我发现这个存储过程在堆栈溢出,但它没有按预期工作.
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
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
ERROR 1326(24000):光标未打开