1

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 ?

tshepang
  • 12,111
  • 21
  • 91
  • 136
abidinberkay
  • 1,857
  • 4
  • 36
  • 68
  • 1
    http://stackoverflow.com/questions/1079949/sql-the-semicolon-or-the-slash/10207695#10207695 –  Mar 18 '14 at 19:37

1 Answers1

10

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

Gary_W
  • 9,933
  • 1
  • 22
  • 40