Sqlplus printing the result twice and with an empt

2019-03-01 05:20发布

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条回答
迷人小祖宗
2楼-- · 2019-03-01 06:00

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

查看更多
登录 后发表回答