2010-12-07 41 views
6

我正在嘗試編寫一個簡單的查詢腳本,該腳本可以獲取表中行的cnt數。不過,我面臨的問題是壓制各種oracle消息。所有我感興趣的是輸出:在腳本中運行sql查詢時抑制郵件

這裏是我的腳本:

#!/usr/bin/ksh 
sqlplus /nolog <<EOF 
connect user/[email protected] 
set serveroutput on 
set heading off 
set feedback off 
select count(*) from table; 
exit; 
EOF 

我的輸出是這樣的:

.desktop% sh sql.ksh 
SQL*Plus: Release 10.2.0.2.0 - Production on Tue Dec 7 12:00:42 2010 
Copyright (c) 1982, 2005, Oracle. All Rights Reserved. 
SQL> Connected. 
SQL> SQL> SQL> SQL> 
     70 
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 
With the Partitioning, OLAP, Data Mining and Real Application Testing options 

我要的是數70沒有任何的消息,讓我可以定期寫入日誌等。我知道我可以解析這個數字,但每當我的查詢或模式發生變化時,我都必須改變它。我不能只是要求mysqlplus壓制所有這些消息嗎?

回答

7

您需要使用的sqlplus -s靜默模式

#!/usr/bin/ksh 
sqlplus -s /nolog <<EOF 
connect user/[email protected] 
set serveroutput on 
set heading off 
set feedback off 
select count(*) from table; 
exit; 
EOF 
+0

我同意通過添加-s,即使是我想看到的那些消息也沒有任何消息。問題是如何隱藏所有這些消息,並只顯示我想看到的消息,例如,如果我添加 dbms_output.put_line('Hello Word') 我想只看到Hello Word。我怎樣才能做到這一點??? – vogash 2013-12-25 10:42:22

4

嘗試-s標誌。例如,

sqlplus /s /nolog <<EOF 

...

6

你必須大寫S選項添加到sqlplus

(附帶甲骨文11.2.0.4.0的SQLPLUS)的幫助信息規定:

-S Sets silent mode which suppresses the display of 
     the SQL*Plus banner, prompts, and echoing of 
     commands. 

的東西,如

$ sqlplus -S /nolog << EOF 
connect user/[email protected] 
set serveroutput on 
set heading off 
set feedback off 
exec package.procedure($1); -- procedure that calls DBMS_OUTPUT procedures ... 
select 2 from dual; 
-- ... 
exit; 
EOF 

你只能得到從輸出DBMS_OUTPUT緩衝區和select語句的結果。