在“ OracleSQLDeveloperSQL 工作表”窗口中打印文本

我正在使用 OracleSQL (在 SQLDeveloper 中,使用 SQL 工作表)。我想在选择之前打印一条语句,如

PRINT 'Querying Table1';
SELECT * from Table1;

我用什么来打印/显示文本输出?它不是 Print,因为它给出了错误: Bind 变量 Table1未声明。数据库管理系统输出。PUT _ LINE 是未知命令。(显然,我是一个没有经验的 SQLDeveloper 和 Oracle 用户。一定有一些打印的同义词,但是我在不知道它是什么的情况下很难找到帮助。)

432380 次浏览

You could set echo to on:

set echo on
REM Querying table
select * from dual;

In SQLDeveloper, hit F5 to run as a script.

You could put your text in a select statement such as...

SELECT 'Querying Table1' FROM dual;

enter image description here

for simple comments:

set serveroutput on format wrapped;
begin
DBMS_OUTPUT.put_line('simple comment');
end;
/


-- do something


begin
DBMS_OUTPUT.put_line('second simple comment');
end;
/

you should get:

anonymous block completed
simple comment


anonymous block completed
second simple comment

if you want to print out the results of variables, here's another example:

set serveroutput on format wrapped;
declare
a_comment VARCHAR2(200) :='first comment';
begin
DBMS_OUTPUT.put_line(a_comment);
end;


/


-- do something




declare
a_comment VARCHAR2(200) :='comment';
begin
DBMS_OUTPUT.put_line(a_comment || 2);
end;

your output should be:

anonymous block completed
first comment


anonymous block completed
comment2
PROMPT text to print

Note: must use Run as Script (F5) not Run Statement (Ctl + Enter)

For me, I could only get it to work with

set serveroutput on format word_wrapped;

The wraped and WRAPPED just threw errors: SQLPLUS command failed - not enough arguments

If you don't want all of your SQL statements to be echoed, but you only want to see the easily identifiable results of your script, do it this way:

set echo on

REM MyFirstTable

set echo off

delete from MyFirstTable;

set echo on

REM MySecondTable

set echo off

delete from MySecondTable;

The output from the above example will look something like this:

-REM MyFirstTable

13 rows deleted.

-REM MySecondTable

27 rows deleted.

The main answer left out a step for new installs where one has to open up the dbms output window.

enter image description here

Then the script I used:

dbms_output.put_line('Start');

Another script:

set serveroutput on format wrapped;
begin
DBMS_OUTPUT.put_line('jabberwocky');
end;

If I ommit begin - end it is error. So for me this is working (nothing else needed):

set serveroutput on;
begin
DBMS_OUTPUT.PUT_LINE('testing');
end;