Sqlplus打印结果两次并用空行 [英] Sqlplus printing the result twice and with an empty line

查看:189
本文介绍了Sqlplus打印结果两次并用空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的是shell脚本,并想使用sqlplus:

I write shell script and want to use sqlplus, when I write:

#!/bin/bash
result=$(sqlplus -s user/pass@DB  << EOF
set trimspool on;
set linesize 32000;
SET SPACE 0;
SELECT MAX(DNNCMNT_ANSWER_TIME)  FROM TKIMEI.DNNCMNT_IMEI_APPRV;
/
exit;
EOF)
echo "$result"

结果在txt文件中(我将其作为ksh sql.sh > result.txt执行):

the result is in txt file (I'm executing it as ksh sql.sh > result.txt):

MAX(DNNCM
---------
10-MAR-14

MAX(DNNCM
---------
10-MAR-14

它会自动在文件开头添加一个空行,并将结果写入两次.

it is automatically putting an empty line at the beginning of file and writing the result twice.

我该如何解决?

推荐答案

删除斜杠.这导致重复上一个命令(选择): http://docs.oracle.com/cd/B10501_01 /server.920/a90842/ch13.htm#1006932

Remove the slash. It's causing the previous command (the select) to be repeated: http://docs.oracle.com/cd/B10501_01/server.920/a90842/ch13.htm#1006932

此外,请与您的DBA讨论设置外部OS身份验证的问题,这样就不必出于安全原因而将密码硬编码在Shell脚本中.设置完成后,您可以仅用斜杠替换登录名/密码组合: http://docs.oracle.com/cd/E25054_01 /network.1111/e16543/authentication.htm#i1007520

Also, talk to your DBA about setting up external OS authentication so you don't have to hardcode the password in a shell script for security reasons. Once set up, you can replace the login/password combo with just a slash: http://docs.oracle.com/cd/E25054_01/network.1111/e16543/authentication.htm#i1007520

这篇关于Sqlplus打印结果两次并用空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆