Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to execute an sql file (a text file containing several SQL statements) against an oracle database from a bash shell command line (e.g. no graphical GUI and no interactive clients)

Something like: sqlplus -f queries.sql ...

The command is expected to execute all the statements in the queries.sql file and exit with an appropriate exit code (e.g. 0 if all queries executed correctly, nonzero otherwise)

share|improve this question
up vote 5 down vote accepted

In a shell script:


sqlplus user/pass@server/DATABASE<<THEEND

-- Change "1" to the desired fatal return code

whenever sqlerror exit 1;




Or you can just run:

sqlplus user/pass@server/DATABASE @yoursqlscript

... and put the whenever sqlerror exit 1; at the top of your .sql script(s).

share|improve this answer
+1, you should also use the -L option so that sqlplus will return immediately with an error if it fails to login. – Vincent Malgrat Jun 28 '12 at 15:17
The Or part of your answer, with sqlplus user/pass@server/DATABASE @yoursqlscript works putting the statement (with an ending ";") at the beginning of the script – a1an Jun 28 '12 at 15:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.