在脚本中运行sql查询时禁止消息

时间:2021-05-08 23:50:48

I am trying to write a simple query-script that gets me cnt of rows in a table. However I am facing problem to suppress all sorts of oracle messages. All I am interested is the output:

我正在尝试编写一个简单的查询脚本,它可以让我获取表中的行数。但是我面临着压制各种oracle消息的问题。我感兴趣的是输出:

Here is my script:

这是我的脚本:

#!/usr/bin/ksh
sqlplus /nolog <<EOF
connect user/pswd@databse
set serveroutput on
set heading off
set feedback off
select count(*) from table;
exit;
EOF

My output looks like this:

我的输出如下:

.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

All I want is the number 70 without any message so that I can write it to logs etc regularly. I know I can parse for the number but I ll have to change that every time my query or schema changes. Can't I just ask mysqlplus to suppress all those messages?

我想要的只是数字70,没有任何消息,所以我可以定期将它写入日志等。我知道我可以解析数字,但每次我的查询或模式更改时我都必须更改它。我不能只是要求mysqlplus来压制所有这些消息吗?

3 个解决方案

#1


10  

You have to add the uppercase S option to sqlplus.

您必须将大写的S选项添加到sqlplus。

The help message (of sqlplus that comes with Oracle 11.2.0.4.0) specifies:

帮助消息(Oracle 11.2.0.4.0附带的sqlplus)指定:

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

With something like

有类似的东西

$ sqlplus -S /nolog << EOF
connect user/pswd@databse
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

you only get the output from the DBMS_OUTPUT buffer and the results from select statements.

您只能获取DBMS_OUTPUT缓冲区的输出和select语句的结果。

#2


7  

You need to use sqlplus -s for silent mode

您需要使用sqlplus -s进行静默模式

#!/usr/bin/ksh
sqlplus -s /nolog <<EOF
connect user/pswd@databse
set serveroutput on
set heading off
set feedback off
select count(*) from table;
exit;
EOF

#3


4  

Try the -s flag. e.g.,

试试-s标志。例如。,

sqlplus /s /nolog <<EOF

...

#1


10  

You have to add the uppercase S option to sqlplus.

您必须将大写的S选项添加到sqlplus。

The help message (of sqlplus that comes with Oracle 11.2.0.4.0) specifies:

帮助消息(Oracle 11.2.0.4.0附带的sqlplus)指定:

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

With something like

有类似的东西

$ sqlplus -S /nolog << EOF
connect user/pswd@databse
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

you only get the output from the DBMS_OUTPUT buffer and the results from select statements.

您只能获取DBMS_OUTPUT缓冲区的输出和select语句的结果。

#2


7  

You need to use sqlplus -s for silent mode

您需要使用sqlplus -s进行静默模式

#!/usr/bin/ksh
sqlplus -s /nolog <<EOF
connect user/pswd@databse
set serveroutput on
set heading off
set feedback off
select count(*) from table;
exit;
EOF

#3


4  

Try the -s flag. e.g.,

试试-s标志。例如。,

sqlplus /s /nolog <<EOF

...