在 Oracle SQL Developer SQL 工作表窗口中打印文本

发布于 2024-07-07 06:45:05 字数 329 浏览 14 评论 0原文

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

PRINT 'Querying Table1';
SELECT * from Table1;

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

I am using Oracle SQL (in SQLDeveloper, using the SQL Worksheet). I would like to print a statement before my select, such as

PRINT 'Querying Table1';
SELECT * from Table1;

What do I use to Print / show text output? It's not Print, because that gives me the error: Bind Variable Table1 is NOT DECLARED. DBMS_OUTPUT.PUT_LINE is an unknown command. (Obviously, I'm an inexperienced SQLDeveloper and Oracle user. There must be some synonym for Print, but I'm having trouble finding help on it without knowing what it is.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

你与昨日 2024-07-14 06:45:05

在此处输入图像描述

进行简单注释:

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

-- do something

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

您应该得到:

anonymous block completed
simple comment

anonymous block completed
second simple comment

如果您想打印变量的结果,这里是另一个示例:

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;

你的输出应该是:

anonymous block completed
first comment

anonymous block completed
comment2

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
入怼 2024-07-14 06:45:05
PROMPT text to print

注意:必须使用
作为脚本运行 (F5)
不是
运行语句(Ctl + Enter)

PROMPT text to print

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

无人接听 2024-07-14 06:45:05

主要答案省略了新安装的一个步骤,必须打开 dbms 输出窗口。

输入图像描述这里

然后我使用的脚本:

dbms_output.put_line('Start');

另一个脚本:

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

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;
烂人 2024-07-14 06:45:05

您可以将 echo 设置为 on:

set echo on
REM Querying table
select * from dual;

在 SQLDeveloper 中,按 F5 以作为脚本运行。

You could set echo to on:

set echo on
REM Querying table
select * from dual;

In SQLDeveloper, hit F5 to run as a script.

冬天的雪花 2024-07-14 06:45:05

您可以将文本放在选择语句中,例如...

SELECT 'Querying Table1' FROM dual;

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

SELECT 'Querying Table1' FROM dual;
旧话新听 2024-07-14 06:45:05

对我来说,我只能让它与

set serveroutput on format word_wrapped;

包装和包装一起工作只是抛出错误:SQLPLUS命令失败 - 没有足够的参数

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

不念旧人 2024-07-14 06:45:05

如果我省略开始 - 结束,那就是错误。 所以对我来说这是有效的(不需要其他任何东西):

set serveroutput on;
begin
DBMS_OUTPUT.PUT_LINE('testing');
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;
冰雪之触 2024-07-14 06:45:05

如果您不希望回显所有 SQL 语句,但只想查看脚本的易于识别的结果,请这样做:

设置回显

REM MyFirstTable

关闭回显

从 MyFirstTable 中删除;

设置回显

REM MySecondTable

关闭回显

从 MySecondTable 中删除;

上面示例的输出将如下所示:

-REM MyFirstTable

删除了 13 行。

-REM MySecondTable

删除了 27 行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文