2017-05-29 128 views
0

我已经编写了一个代码,它在执行后会给我所需的输出。unix shell脚本中的SQL查询

下面是代码:

#!/bin/ksh 

sqlplus/<< !EOF! 
set verify off 
set heading off 
set pagesize 0 
set feedback off; 

select * from account where account_name='23553558101'; 

exit; 
!EOF!` 

的问题是,我得到的所有非必需的东西太多,但我只需要输出没有其他的东西与沿。

下面是我得到的输出:

$ ./sqltest 

SQL*Plus: Release 10.2.0.1.0 - Production on Mon May 29 17:32:52 2017 

Copyright (c) 1982, 2005, Oracle. All rights reserved. 

Connected to: 
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production 
With the Partitioning, OLAP, Data Mining Scoring Engine and Real Application Testing options 

17:32:52 [email protected] > 17:32:52 [email protected] > 17:32:52 [email protected] > 17:32:52 [email protected] > 17:32:52 [email protected] > 17:32:52 [email protected] > 56566309 23553558101      20-05-2017 05:41:00   57194135  20000184   64,56 
20-05-2017 00:00:00 340393871   338845845   500    0 
         0 

17:32:52 [email protected] > 17:32:52 [email protected] > Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production 
With the Partitioning, OLAP, Data Mining Scoring Engine and Real Application Testing options 
+0

这不是完全清楚你非需要的东西的意思,但我猜Oracle连接信息,所以如果是这样的话,你只需要需要调用“sqlplus -s /”来建立一个无声的sql连接 – Mike

+0

我写下面的代码:#!/ bin/ksh sqlplus -s/nolog <<!EOF! 集上 集标题关闭 组trimout回声关闭 集合页大小0 组反馈关闭 SELECT * FROM帐户其中ACCOUNT_NAME = '23553558101'; 退出; !EOF!' 我收到下面的错误:$ ./sqltest SP2-0640:没有连接 – User123

+0

为什么在你的/你的调用“sqlplus -s/nolog”之后有一个nolog部分? 从sql的角度来看,你要求连接没有用户使用nolog作为密码。您可以连接“sqlplus -s用户名/密码”或使用数据库密码文件“sqlplus -s /” – Mike

回答

1

当你在一个shell脚本用sqlplus是更好地登录使用静音模式“的sqlplus -s”来剿登录的消息,也删除sql提示符“sql>”。

更进一步,你需要改变像一些变量:

标题 - 它不会显示查询结果的头(列的名字更精确)

set heading off 

反馈 - 在查询选择后它不会返回行数。

set feedback off 

校验 - 使用的情况下,显示值你有替代变量

set verify off 

列给出以上是在缺省情况下,因此最好关闭它们,如果你想要一个干净的显示器(只是结果),如果你的sqlplus的结果将被一个shell变量收集,那么它在我的opionion中是强制性的。 您可以检查手册,了解更多有关sqlplus的系统变量: https://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve040.htm#SQPUG060