gpt4 book ai didi

mysql - 光标未打开错误

转载 作者:行者123 更新时间:2023-11-29 01:33:16 25 4
gpt4 key购买 nike

我想要处理表“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

我收到一个错误:

错误 1326 (24000): 光标未打开

最佳答案

你好像忘了在循环之前声明打开游标

open col_names;
the_loop: LOOP
...

关于mysql - 光标未打开错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4955231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com