基本问题:基本的 PL/SQL 控制台输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10150163/
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
Rudimentary issue: basic PL/SQL console output?
提问by Justin Cave
I am using SQL Developer and want to output the contents of a variable to the console using DBMS_OUTPUT.PUT_LINE(). I am running the following code that adds the numbers 1 through 5 inclusive but I'm not seeing any output.
我正在使用 SQL Developer 并希望使用 DBMS_OUTPUT.PUT_LINE() 将变量的内容输出到控制台。我正在运行以下代码,将数字 1 到 5 相加,但我没有看到任何输出。
SET SERVEROUTPUT ON;
DECLARE
n_counter NUMBER := 5; -- Substitute this variable
n_sum NUMBER := 0;
BEGIN
WHILE n_counter != 0
LOOP
n_sum := n_sum + n_counter;
n_counter := n_counter -1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(n_sum);
END;
Additionally, do you Know of better resources for troubleshooting issues than the incredibly dense Oracle PL/SQL documentation? [similar to Java SE7 API?]
此外,您是否知道比极其密集的 Oracle PL/SQL 文档更好的故障排除资源?[类似于Java SE7 API?]
回答by Justin Cave
Since you are using SQL Developer, you have a couple of options.
由于您使用的是 SQL Developer,因此您有几个选择。
In SQL Developer, go to View | DBMS Output
to ensure that the DBMS Output window is visible. In the DBMS Output window, choose the "plus" icon and select the connection that you want to write data to the DBMS Output window. Then run the PL/SQL block in the SQL Worksheet window using the right arrow (Ctrl+Enter in Windows). You'll see the output appear in the DBMS Output window.
在 SQL Developer 中,转到以View | DBMS Output
确保 DBMS 输出窗口可见。在 DBMS 输出窗口中,选择“加号”图标并选择要将数据写入 DBMS 输出窗口的连接。然后使用向右箭头(在 Windows 中为 Ctrl+Enter)在 SQL 工作表窗口中运行 PL/SQL 块。您将看到输出出现在 DBMS 输出窗口中。
Alternately, you can put both the SQL*Plus SET SERVEROUTPUT ON
command and the PL/SQL block in the SQL Worksheet and run it as a script (F5 in Windows). That will display the output immediately below the "anonymous block completed" message in the Script Output window.
或者,您可以将 SQL*PlusSET SERVEROUTPUT ON
命令和 PL/SQL 块放在 SQL 工作表中,并将其作为脚本运行(在 Windows 中为 F5)。这将在“脚本输出”窗口中“匿名块已完成”消息的正下方显示输出。
Note: Dbms Output in Oracle Sql Developer doesn't show null in the output window. It moves to a new line, but until it will return something else than null, you'll not know all the previous nulls are there.
注意:Oracle Sql Developer 中的 Dbms 输出不会在输出窗口中显示 null。它移动到一个新行,但直到它返回空值以外的其他值之前,您不会知道所有先前的空值都在那里。