Run Oracle SQL script and exit from sqlplus.exe via command prompt
Solution 1:
Another way is to use this command in the batch file:
echo exit | sqlplus user/pass@connect @scriptname
Solution 2:
I found this to be the best solution and it works in a terminal or within a script:
echo @scriptname | sqlplus username/password@connect
Solution 3:
Realizing now that your problem may be with the sql file itself, realize that sqlplus needs to be told to exit. The way I do this is:
select * from dual; quit; /
(The slash is important. It tells sqlplus to execute the statemet(s) above it.)
Solution 4:
The best way to hide user information and exits is:
exit | sqlplus -S user/pwd@server @script.sql
exit
is supplied to output of sqlplus forcing it to quit. -S
suprresses all server output other then sql query in the script.
Solution 5:
You can also do this in your shell script.
sqlplus /nolog <<EOF
connect user/pass
@run_some_file.sql
select * from dual;
EOF
You might need to escape the ";" with a \.