基本问题:基本的 PL/SQL 控制台输出? [英] Rudimentary issue: basic PL/SQL console output?

查看:108
本文介绍了基本问题:基本的 PL/SQL 控制台输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SQL Developer 并想使用 DBMS_OUTPUT.PUT_LINE() 将变量的内容输出到控制台.我正在运行以下代码,将数字 1 到 5 相加,但我没有看到任何输出.

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.

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;

此外,您是否知道比极其密集的 Oracle PL/SQL 文档更好的故障排除资源?[类似于Java SE7 API?]

Additionally, do you Know of better resources for troubleshooting issues than the incredibly dense Oracle PL/SQL documentation? [similar to Java SE7 API?]

推荐答案

由于您使用的是 SQL Developer,因此您有几个选择.

Since you are using SQL Developer, you have a couple of options.

在 SQL Developer 中,转到 View |DBMS 输出 以确保 DBMS 输出窗口可见.在 DBMS 输出窗口中,选择加号"图标并选择要将数据写入 DBMS 输出窗口的连接.然后使用向右箭头(在 Windows 中为 Ctrl+Enter)在 SQL 工作表窗口中运行 PL/SQL 块.您将看到输出显示在 DBMS 输出窗口中.

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*Plus SET SERVEROUTPUT ON 命令和 PL/SQL 块放在 SQL 工作表中,并将其作为脚本运行(在 Windows 中为 F5).这将在脚本输出"窗口中匿名块已完成"消息的正下方显示输出.

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.

注意:Oracle Sql Developer 中的 Dbms 输出不会在输出窗口中显示 null.它移动到一个新行,但直到它返回空值以外的其他值之前,您不会知道所有先前的空值都在那里.

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.

这篇关于基本问题:基本的 PL/SQL 控制台输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆