2012-04-10 122 views
3

Im在.sql文件中的Script下執行。我正在使用Windows命令行控制檯來調用sqlplus。當腳本終止一切看起來不錯時,除了我看不到INSERT語句添加的記錄數。你可以看到輸出也低於:SQLPLUS不打印受影響的行數

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,我可以看到添加的行數(請參閱下面的**標記行)。

OUTPUTDISPLAYED蟾蜍

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'這個腳本?

+0

的可能重複的[PLSQL過程內INSERT沒有告訴行數插入了多少行](http://stackoverflow.com/questions/4139945/insert-inside-plsql-procedure-does-not-tell-how-many-rows-were-inserted) – paxdiablo 2012-04-10 02:36:07

+0

不會出現INSERT是但是,在一個pl/sql塊中。 – DCookie 2012-04-10 03:16:30

回答

2

SQL * Plus不會輸出中的行數,但你可以用類似明確地做到這一點:

INSERT blah blah blah; 
DBMS_OUTPUT.put_line (SQL%ROWCOUNT); 
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/[email protected] 

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塊內嗎?這會壓制消息。

3

SET FEEDBACK ON的默認閾值爲6.如果您希望獲得較少數量的反饋,請使用「SET FEEDBACK 1」。

+0

這對我來說沒有什麼不同。 – DCookie 2012-04-10 15:22:33

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

使用

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