Contents
How to use sqlplus with a shell script?
Some of the other answers here inspired me to write a script for automating the mixed sequential execution of SQL tasks using SQLPLUS along with shell commands for a project, a process that was previously manually done. Maybe this (highly sanitized) example will be useful to someone else:
What are the variables in sqlplus in Bash?
The variables containing the credentials are included for illustration, but for security I actually source them from another file. If you wanted to handle multiple database connections, you could easily modify the function to accept the hoststring as an additional parameter.
How to use sqlplus as a DBA tool?
My #1 Oracle DBA tool is sqlplus – I use it to automate DBA tasks directly on the Oracle Server from shell scripts. I often put the output of sqlplus -s in a shell variable and use it for further processing. I also wrap the sqlplus script output in a shell function and pipe it’s output to egrep filtering.
What does the s flag on sqlplus mean?
After all – there would be no reason to make that initial connection only to have the script reconnect again. The -s flag tells sqlplus to be banner silent and not prompt for any input such as username/password or variable substitution.
How to use sqlplus to access Oracle Server?
If your only intention is to login as sysdba once and then execute some commands directly on the Oracle Server then you can skip the /nolog option and instead use / as sysdba. The / tells sqlplus to use OS level authentication and the as sysdba tells sqlplus that you want to gain access to the Oracle server with…
What happens when SQL Plus is rolled back?
If an SQL error occurs the transaction will be rolled back and SQL*Plus will be exited. The error code that SQL*Plus is an OS-system depended value that signals an error is the default, so you must not execute this command.