2

I've been looking everywhere, and the posts suggest to pipe the echo exit | sqlplus @script.sql but my script contains PL/SQL statements, that take input, so as soon as the PROMPT message is outputted, the exit kicks in and the script exits.

Here's the linux call

alias sql 'sqlplus -s user/pass'

sql @test.sql

The script executes fine and does the INSERT in the DB, but then it just waits for me to type the exit once it executes. Any ideas?

1
  • Are you not able to modify the script? Commented Aug 9, 2016 at 22:15

1 Answer 1

4

The obvious thing to do is to modify your script to have exit at the end. If you can't do that you can create a temporary file that does it, e.g.:

(cat test.sql && echo exit) > /tmp/test_$$.sql
sql @/tmp/test_$$.sql
rm -f /tmp/test_$$.sql

The $$ in the file name is substituted with the current process's ID (PID), so if the script is run twice simultaneously each will get a different file name; and then it's removed at the end. (You can do a protective delete first, or check it doesn't already exist, just in case an earlier removal failed somehow).

Sign up to request clarification or add additional context in comments.

2 Comments

I did have exit at the end of the script, but the pl/sql didn't recognise it
The exit needs to be right at the end of your script, after any PL/SQL (or plain SQL) statements. If your script ends with a PL/SQL block and its terminating / then the exit goes after that, on a new line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.