Rudimentary issue: basic PL/SQL console output? [duplicate]

余生颓废 提交于 2019-12-17 22:46:02

问题


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;

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


回答1:


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

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.

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.

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.



来源:https://stackoverflow.com/questions/10150163/rudimentary-issue-basic-pl-sql-console-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!