Sqlplus printing the result twice and with an empty line

泄露秘密 提交于 2019-12-31 04:02:26

问题


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"

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.

How can I fix it ?


回答1:


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

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



来源:https://stackoverflow.com/questions/22488591/sqlplus-printing-the-result-twice-and-with-an-empty-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!