Shell script which runs sql script

Hi all,

I need a shell script which runs a sql script but I couldn't find how to finish it. This is the code that I have:

#! /usr/bin/ksh
export SHELL=/bin/ksh
export ORACLE_SID=database
export ORACLE_HOME=/opt/oracle/product/9.2.0.8
sqlplus user[/password][@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=database)(PORT=1637))(CONNECT_DATA=(SERVICE_NAME=database)))] [AS {SYSOPER}] <<EOF @/path/path/path/scriptname.sql
EXIT
EOF

When I run this code I am receiving the next message error:

Usage: SQLPLUS [ [<option>] [<logon>] [<start>] ]
where <option> ::= -H | -V | [ [-L] [-M <o>] [-R <n>] [-S] ]
<logon> ::= <username>[/<password>][@<connect_string>] | / | /NOLOG
<start> ::= @<URI>|<filename>[.<ext>] [<parameter> ...]
"-H" displays the SQLPlus version banner and usage syntax
"-V" displays the SQL
Plus version banner
"-L" attempts log on just once
"-M <o>" uses HTML markup options <o>
"-R <n>" uses restricted mode <n>
"-S" uses silent mode

Any idea what I should change?

Thank you! :slight_smile:

I haven't called a script from within sqlplus, but your connection string looks off.

sqlplus username/password@dbhost:1637/dbsid <<EOF
desc somedbview;
quit
EOF

That command works ok from my end.

thanks for your help, but it did not work.. another idea?

well, finally my shell is done... my problem was that my user to access to database has a $ like abc$dfgh so, unix takes as a variable then I had to put quotation marks as:

sqlplus -S 'abc$dfgh/password@database' <<EOF @/path/path/path/scriptname.sql

and It worked!