chu_cun 发表于 2004-11-15 12:04:12

在shell脚本中如何实现将select的结果输出到文本文件

还有在脚本中连接数据库能不能不显示呀,就是在脚本中执行sqlplus uname/pwd时
不出现界面
sqlplus uname/pwd >> #不出现提示
select * from mytable > out.txt
exit
以上是瞎写的,就是想表达我的意思:)

gucuiwen 发表于 2004-11-15 13:32:15

sqlplus 的spool 功能不是能专门实现这个功能的吗???

sqlplus> spool outfile.txt
sqlplus> spool on开始记录

sqlplus> select * from sometable;

sqlplus> spool off停止记录

sqlplus > help spool 查看用法.

chu_cun 发表于 2004-11-15 15:26:32

我是利用脚本来执行的
不要手工进入sqlplus,
sqlplus uname/pwd < EOF
@sqlfile
exit
类似这种操作

gucuiwen 发表于 2004-11-15 16:12:57

spool 命令也可以放在脚本里.

chu_cun 发表于 2004-11-15 17:20:48

我关健的问题是如何关闭在sqlplus uname/pwd (登录)时所出现的交互信息

chu_cun 发表于 2004-11-15 17:26:13

我现在的脚本是这样的
sqlplus uname/pwd << EOF
set spool /home/test/data.txt
select * from tab
spool off
exit
head -20 > newdata.txt
但是登录界面及操作过程(select)的结果还是显示
但完成了得到数据文件的要求
还有head -20 > newdata.txt没有执行,为什么??

gucuiwen 发表于 2004-11-15 21:22:13

你在脚本的最前面 set echo off

或者 set feedback off 看看

我记得sqlplus有这个功能关闭这些输出信息的。

chu_cun 发表于 2004-11-16 10:03:47

已经OK了谢谢各位,
但是我不理解“<<”代表什么操作,
它的后面有时会跟不同的东西如 <<+ 、 <<! 、<< EOF
都是什么意思呀
页: [1]
查看完整版本: 在shell脚本中如何实现将select的结果输出到文本文件