SQLPLUS不打印受影响的行数

时间:2012-04-10 02:17:43

标签: sql oracle sqlplus

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

SCRIPT

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影响的行数,即使我通过简单的'sqlplus'运行这个脚本?

5 个答案:

答案 0 :(得分:3)

SQL * Plus不会输出行数,但您可以使用以下内容显式执行:

INSERT blah blah blah;
DBMS_OUTPUT.put_line (SQL%ROWCOUNT);

答案 1 :(得分:3)

SET FEEDBACK ON的默认阈值为6.如果您想要较少数字的反馈,请使用" SET FEEDBACK 1"。

答案 2 :(得分: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;
/

答案 3 :(得分: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块内?这会压制消息。

答案 4 :(得分:0)

rem to see Pl/SQL "print" statements:
set serveroutput on