oracle 为什么我看不到这个 PL/SQL 块的输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4124624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why do I see no output from this PL/SQL block?
提问by andandandand
I'd like a code sample.
我想要一个代码示例。
I'm tryng this:
我正在尝试这个:
DECLARE
var NUMBER;
BEGIN
/*N.B. for loop variables in pl/sql are new declarations, with scope only inside the loop */
FOR var IN 0 .. 10 LOOP
DBMS_OUTPUT.put_line(var);
END LOOP;
IF (var IS NULL) THEN
DBMS_OUTPUT.put_line('var is null');
ELSE
DBMS_OUTPUT.put_line('var is not null');
END IF;
END;
and getting no output (though I know it's not a infinite loop). Why is this one not printing?
并且没有输出(尽管我知道这不是无限循环)。为什么这个不打印?
edit: The not-printing code was fixed via the database manager interface.
编辑:非打印代码已通过数据库管理器界面修复。
回答by Justin Cave
A LOOP without an EXIT statement is one way to generate an infinite loop in PL/SQL
没有 EXIT 语句的 LOOP 是在 PL/SQL 中生成无限循环的一种方式
BEGIN
LOOP
null;
END LOOP;
END;
You could also write a WHILE loop that never ends
你也可以写一个永不结束的 WHILE 循环
BEGIN
WHILE( true )
LOOP
NULL;
END LOOP;
END;
回答by Jay S
If your problem is that you are getting no output, then you may not have enabled DBMS OUTPUT yet. You can do that with:
如果您的问题是没有输出,那么您可能还没有启用 DBMS OUTPUT。你可以这样做:
set serveroutput on
回答by Gary Myers
A loop containing a DBMS_OUTPUT.PUT_LINE will not be infinite (if serveroutput is enabled) as, eventually, it will fill the entire output buffer or the available memory. The limit used to be about 1 million bytes so would get hit quite quickly. If it goes to fill up the entire computer memory, that can take quite some time.
包含 DBMS_OUTPUT.PUT_LINE 的循环不会是无限的(如果启用了 serveroutput),因为最终它会填满整个输出缓冲区或可用内存。过去的限制大约是 100 万字节,因此很快就会达到。如果它填满整个计算机内存,那可能需要相当长的时间。
On infinite loops, I went through a bad patch of forgetting to go to the next element in a table.
在无限循环中,我遇到了忘记转到表中下一个元素的糟糕情况。
DECLARE
type typ_tab is table of varchar2(10) index by pls_integer;
t_tab typ_tab;
v_ind number;
BEGIN
t_tab(10) := 'A';
t_tab(20) := 'B';
v_ind := t_tab.first;
WHILE v_ind IS NOT NULL LOOP
dbms_output.put_line(t_tab(v_ind));
v_ind := t_tab.next(v_ind); --Forget this and it loops forever
END LOOP;
END;
Once they get into such a loop, the session may need to be killed by the DBA.
一旦进入这样的循环,会话可能需要被 DBA 终止。
回答by Quassnoi
Don't know why would you need it, but:
不知道你为什么需要它,但是:
BEGIN
WHILE 1 = 1
LOOP
NULL;
END LOOP;
END;