I\'m having a problem trying to run my sql script into oracle using sqlplus. The script just populates some dummy data:
DECLARE
role1Id NUMBER;
user1Id
The command line
sqlplus username/password@server/dbname @Setup.sql
mentioned above means that sqlplus
should execute the script Setup.sql
and wait further commands interactively (if script does not do exit
explicitly). This is a normal behavior of sqlplus
.
sqlplus
terminates in three cases:
WHENEVER
plsql-command)exit
(both interactive and sript)Either from interactive mode or from script you can send ^Z
character to softly terminate input flow. Interactively you just press Ctrl+Z,Enter
.
And, of course, you may redirect STDIN, and take it from file, not from keyboard. There are two similar ways to do this:
1) sqlplus username/password@server/dbname<Setup.sql
2) echo @Setup.sql|sqlplus username/password@server/dbname
In both cases sqlplus
will terminate after the script execution because of EOF
in the input flow.
You need to either put an exit
at the end of the script, or run it as sqlplus username/password@server/dbname < Setup.sql
(i.e. redirected input, <
instead of @
). You can check if that's the issue by just typing 'exit' in the hanging session.
If it is really hanging, have you committed or rolled back the execution from Developer?
I was seeing this problem as well with certain scripts that would execute fine in a client like TOAD, but when being executed via SQLPlus with the @script directive instead of hanging, the SQLPlus client would return a prompt with a number on it which corresponded to the number of lines in the script being executed (+1).
For example, if we executed a script named 'doit.sql' that had 70 lines we would start SQLPlus with the appropriate command and enter:
> @doit.sql
Then we would see:
71:
Pressing enter at this point would return
72:
We were able to get these scripts executed by entering /
at the prompt and pressing enter.
The Simple answer
Make sure you put both 'end;' and in final line put '/'
It will run with ease.
Issue is because of SQLplus was running from the oracle client home and it was crashing on running the startup upgrade command.
Run the sqlplus from the non-client oracle home and tried the commands then it works as expected. so resolution is to run the sqlplus from the main oracle home instead of oracle client home.
Instead of using the /
at the prompt, ensure that your query in the doit.sql ends with a semicolon.