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

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

问题描述

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

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 Output以确保"DBMS输出"窗口可见.在"DBMS输出"窗口中,选择加号"图标,然后选择要将数据写入"DBMS输出"窗口的连接.然后,使用向右箭头(在Windows中为Ctrl + Enter)在SQL Worksheet窗口中运行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.它会移到新行,但是直到返回除null之外的其他内容,您才知道以前所有的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天全站免登陆