3

我在 .sql 文件中执行下面的脚本。我正在使用 Windows 命令行控制台来调用 sqlplus。当脚本终止时,一切看起来都很好,除了我看不到 INSERT 语句添加的记录数。您还可以在下面看到输出:

脚本

WHENEVER SQLERROR EXIT 1 ROLLBACK
WHENEVER OSERROR EXIT 1 ROLLBACK
SET FEEDBACK  ON 
SET VERIFY ON
BEGIN
DBMS_OUTPUT.put_line('Output Nothing');
END;
/
INSERT INTO .........

COMMIT;
QUIT;
/

输出显示

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 9 22:08:47 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

PL/SQL procedure successfully completed.

Commit complete.

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64
bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

当我在 TOAD/SQLNavigator 之类的工具上执行相同的 SQL 时,我可以看到添加的行数(参见下面的 ** 标记行)。

TOAD 上显示的输出

Processing ...
SET FEEDBACK  ON 

SQL*Plus command ignored.
Processing ...
SET VERIFY ON


SQL*Plus command ignored.
Processing ...
BEGIN
DBMS_OUTPUT.put_line('Doing Nothing');
END;

Doing Nothing
Processing ...
INSERT INTO .......

**11 row(s) inserted**

Processing ...
COMMIT

Processing ...
QUIT;

SQL*Plus command ignored.

你能告诉我哪个设置可能会帮助我获得受此 SQL 影响的行数,即使我通过 simple 运行此脚本'sqlplus'

4

5 回答 5

3

SQL*Plus 不会输出行数,但您可以通过以下方式显式执行此操作:

INSERT blah blah blah;
DBMS_OUTPUT.put_line (SQL%ROWCOUNT);
于 2012-04-10T02:25:07.597 回答
3

SET FEEDBACK ON 的默认阈值为 6。如果您希望反馈较少的数字,请使用“SET FEEDBACK 1”。

于 2012-04-10T04:12:15.667 回答
1

利用

set echo on
set autotrace on 

在这种情况下显示执行的命令和有关语句的统计信息插入的行数

WHENEVER SQLERROR EXIT 1 ROLLBACK
WHENEVER OSERROR EXIT 1 ROLLBACK
SET FEEDBACK  ON 
SET VERIFY ON
set echo on
set autotrace on
BEGIN
DBMS_OUTPUT.put_line('Output Nothing');
END;
/
INSERT INTO .........

COMMIT;

QUIT;
/
于 2012-05-01T10:39:59.903 回答
0
rem to see Pl/SQL "print" statements:
set serveroutput on 
于 2012-04-10T15:22:33.977 回答
0

似乎适用于 11g 客户端:

C:\>sqlplus user/pw

SQL*Plus: Release 11.2.0.1.0 Production on Mon Apr 9 21:12:12 2012

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> insert into testing (select 1,'XX' from dual connect by level < 11);

10 rows created.

SQL>

我不认为 10g 客户端的工作方式不同,但我现在无法测试它。

编辑:

与 10g SQLPlus 相同。我今天运行了您的确切脚本:

C:\>sqlplus user/pw@db

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Apr 10 09:12:26 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

DB> WHENEVER SQLERROR EXIT 1 ROLLBACK
DB> WHENEVER OSERROR EXIT 1 ROLLBACK
DB> SET FEEDBACK  ON
DB> SET VERIFY ON
DB> BEGIN
  2      DBMS_OUTPUT.put_line('Output Nothing');
  3  END;
  4  /
Output Nothing

PL/SQL procedure successfully completed.

DB> insert into xx (select 'AA' from dual connect by level < 10);

9 rows created.

DB> COMMIT;

Commit complete.

DB> QUIT;
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

C:\>

我插入 1 行还是 9 行都没关系。我收到了消息。我猜你的脚本示例中遗漏了一些东西。INSERT 是否在 BEGIN/END 块内?那会压制消息。

于 2012-04-10T03:17:10.763 回答