一个简单的循环问题

发布于 2024-10-09 15:57:22 字数 439 浏览 0 评论 0原文

CREATE DEFINER = `dba`@`xx.xx.xx.3` PROCEDURE `oninjadb`.`TESTLOOPER`()
LANGUAGE SQL
DETERMINISTIC
NO SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN

DECLARE counter INT default 0;


simple_loop: LOOP
SET counter=counter+1;
select counter;
 IF counter=100 THEN
    leave simple_loop;

END IF;
end loop simple_loop;
END

好吧,一个简单的循环问题,从谷歌搜索复制而来。唯一的问题是循环不会经过多次,因此输出为 1,仅此而已。我知道这是一个简单的循环,但我需要得到它,以便继续解决更复杂的问题。提前致谢...

CREATE DEFINER = `dba`@`xx.xx.xx.3` PROCEDURE `oninjadb`.`TESTLOOPER`()
LANGUAGE SQL
DETERMINISTIC
NO SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN

DECLARE counter INT default 0;


simple_loop: LOOP
SET counter=counter+1;
select counter;
 IF counter=100 THEN
    leave simple_loop;

END IF;
end loop simple_loop;
END

Okay a simple loop problem, copied from a google search. The only problem is that the loop won't pass thru more than once, so the output is 1 and that's it. I know this is a simple loop, but I need to get it so I move on to more complicated problems. Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

<逆流佳人身旁 2024-10-16 15:57:22

您的程序实际上正在运行 100 个查询。 第一个查询返回数字为 1 的结果。其他 99 个结果集返回正确的数字。

过程能够从多个查询返回多个结果集。您读回这些不同结果集的能力取决于您使用的 API。

Your procedure is actually running 100 queries. The first query is returning a result with the number 1. The 99 other results sets are returning the correct numbers.

Procedures are able to return multiple result sets from multiple queries. Your ability to read back those different result sets depends on the API you are using.

〆一缕阳光ご 2024-10-16 15:57:22

这可能会让你重回正轨:)

drop procedure if exists test_looper;

delimiter #

create procedure test_looper
(
in p_max int unsigned
)
proc_main:begin

declare v_counter int unsigned default 0;

if p_max is null or p_max <= 0 then
    leave proc_main;
end if;

while v_counter < p_max do
    select v_counter;
    set v_counter=v_counter+1;
end while;

end proc_main#

delimiter ;


call test_looper(10);

this might get you back on track :)

drop procedure if exists test_looper;

delimiter #

create procedure test_looper
(
in p_max int unsigned
)
proc_main:begin

declare v_counter int unsigned default 0;

if p_max is null or p_max <= 0 then
    leave proc_main;
end if;

while v_counter < p_max do
    select v_counter;
    set v_counter=v_counter+1;
end while;

end proc_main#

delimiter ;


call test_looper(10);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文