-1

I am new to writing shell scripts. I want to connect to database and execute a simple query. Here is what i am trying

. /home/oracle/db_env.sh
sqlplus system/*****
select * from dual;

but when i execute this script i get nothing. when i exit out of sqlplus i get

bash: db.sh: line 3: syntax error near unexpected token `from'
bash: db.sh: line 3: `select * from dual;'

Kindly guide me how to.

Usman Riaz
  • 2,920
  • 10
  • 43
  • 66

1 Answers1

0

Problem is that once your 'sqlplus system/****' executes, it is entering sqlplus command prompt, next line 'select * from dual;' is not passed by bash to that sqplus application prompt, and it is executed by bash directly.

You probably need something along like these suggestions:

https://stackoverflow.com/a/10278103/2002557

specifically something like:

/home/oracle/db_env.sh:

sqlplus -s <<EOF system/*****@<host name>/<db name>
select * from dual;
select something from somwhere;
# etc.
EOF
Jenya G
  • 504
  • 3
  • 8