简体   繁体   中英

SQLPLUS Doesn't print number of rows affected

Im executing below Script in a.sql file. I'm using Windows Command line console to invoke sqlplus. When script terminates everything looks good, except that I couldn't see number of records added by the INSERT statement. You can see the Output also below:

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;
/

OUTPUT DISPLAYED

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

When I execute the same SQL on a tool like TOAD/SQLNavigator, I could see the number of rows added (See ** marked line below).

OUTPUTDISPLAYED ON 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.

Can you tell me which setting probably will help me geting numbers of rows impacted by this SQL, even when I run this script through simple 'sqlplus' ?

SQL*Plus doesn't ouput the row count but you can do it explicitly with something like:

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

The default threshold for SET FEEDBACK ON is 6. If you want feedback on a fewer number, use "SET FEEDBACK 1".

use

set echo on
set autotrace on 

which display the command executed and statistics about the statement in this case the number of rows inserted

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;
/

Seems to work for me with the 11g client:

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>

I didn't think the 10g client worked differently, but I can't test it right now.

EDIT:

Works the same with 10g SQLPlus. I ran your exact script today:

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:\>

It doesn't matter if I insert 1 row or 9. I get the message. I am guessing there's something you're leaving out of your script example. Is the INSERT inside a BEGIN/END block? That would suppress the message.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM