基本问题:基本的PL/SQL控制台输出?

时间:2021-08-31 06:32:52

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?]

1 个解决方案

#1


44  

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中,查看| DBMS输出以确保DBMS输出窗口是可见的。在DBMS输出窗口中,选择“加号”图标并选择要将数据写入DBMS输出窗口的连接。然后使用右箭头在SQL工作表窗口中运行PL/SQL块(在Windows中按Ctrl+Enter)。您将在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*Plus设置的SERVEROUTPUT放在命令上,也可以将PL/SQL块放在SQL工作表中,并将其作为脚本运行(Windows中的F5)。这将在脚本输出窗口中的“匿名块完成”消息的下方显示输出。

#1


44  

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中,查看| DBMS输出以确保DBMS输出窗口是可见的。在DBMS输出窗口中,选择“加号”图标并选择要将数据写入DBMS输出窗口的连接。然后使用右箭头在SQL工作表窗口中运行PL/SQL块(在Windows中按Ctrl+Enter)。您将在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*Plus设置的SERVEROUTPUT放在命令上,也可以将PL/SQL块放在SQL工作表中,并将其作为脚本运行(Windows中的F5)。这将在脚本输出窗口中的“匿名块完成”消息的下方显示输出。