patternMinor
How, if possible, can an .sql file be executed against an oracle database from a bash script
Viewed 0 times
fromscriptcanfilesqlagainstdatabasepossibleexecutedhow
Problem
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)
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)
Solution
In a shell script:
Or you can just run:
... and put the
#!/bin/bash
sqlplus user/pass@server/DATABASE<<THEEND
-- Change "1" to the desired fatal return code
whenever sqlerror exit 1;
@yoursqlscript.sql
quit;
THEENDOr 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).Code Snippets
#!/bin/bash
sqlplus user/pass@server/DATABASE<<THEEND
-- Change "1" to the desired fatal return code
whenever sqlerror exit 1;
@yoursqlscript.sql
quit;
THEENDsqlplus user/pass@server/DATABASE @yoursqlscriptContext
StackExchange Database Administrators Q#20106, answer score: 5
Revisions (0)
No revisions yet.