Oracle中使用循环的前8个平方数?
如何在Oracle中使用loop计算前8个平方数Oracle中使用循环的前8个平方数?,oracle,Oracle,如何在Oracle中使用loop计算前8个平方数 declare total integer; i integer; begin total := 0; i := 1; loop total := total *i; i := i*total; exit when i > 8; end loop; dbms_output.put_line('the total is ' || total); end;
declare
total integer;
i integer;
begin
total := 0;
i := 1;
loop
total := total *i;
i := i*total;
exit when i > 8;
end loop;
dbms_output.put_line('the total is ' || total); end;
请仔细检查此片段:
i := 1;
loop
total := total *i;
i := i*total;
exit when i > 8;
end loop;
i>8时有退出当i
大于8时,应该退出循环的code>命令,但i
在循环中始终为1,因此循环是无限的,您永远不会得到任何结果。
必须使用i:=i+1在循环中的某个位置递增i
som代码>指令 这不是作业,而是问题的解决方案
SELECT LEVEL * LEVEL squares
FROM DUAL
CONNECT BY LEVEL <= 8;
前8个平方数,为什么是100?此外,您可能会认为这是PL/SQL类中的家庭作业,因此简单的SQL解决方案不会有多大帮助。@muthguy是的,您是对的,谢谢您的评论,我已经更正了我的答案。欢迎使用堆栈溢出。请复习。您已经尝试过什么来发现问题?问题应该显示研究的证据和自己解决问题的尝试,你的特定编码相关问题的清晰轮廓,以及a中的任何相关代码,因此我们有足够的信息能够提供帮助。
1
4
9
16
25
36
49
64