Normally starting the command-line version of sql*plus (sqlplus.exe) would retain the current working folder, allowing a script that is stored in that same folder to be run with the @ command.
D:Folder>sqlplus user/pwd@sid
SQL> host cd
D:Folder
SQL> @myscript.sql
(myscript runs)
However, on some machines (perhaps those that have received some particular update), this behaviour has recently changed, such that if the current drive was something other than C:, then the current directory would be changed to C:WINDOWS.
When I run sqlplus (from a Windows Command-Prompt window), I expect that from the SQL> prompt, that the current working directory (as displayed by a HOST CD
command) would be the same folder as where I started from. Where this was not on C:, then I found that the current working directory inside sqlplus was changed to C:WINDOWS.
D:Folder>sqlplus user/pwd@sid
SQL> host cd
C:WINDOWS
SQL> @myscript.sql
SP2-031: unable to open file "myscript.sql"
In order to run my script, I need to now specify an absolute path.
SQL> @D:Foldermyscript.sql
If I have used any paths in the script, such as on a SPOOL command, these too need to be changed to provide some directory information. e.g. SPOOL log.txt
would try to write to log.txt in C:WINDOWS, rather than D:Folder.
If I run the command host cd D:
I can see that the current directory on D: has not changed, only that the current drive has been changed from D: to C:.
I should therefore be able to run the script using just the drive letter.
SQL> @D:myscript.sql
SP2-031: unable to open file "D:myscript.sql"
Note that the error message reports that the location that sqlplus looked for the file in, was D: even though no backslash was supplied in the command. This feels like a bug.
However, the following form did work, by specifying ‘.’ (meaning the current directory):
@SQL> @D:.myscript.sql
(myscript runs)
If I start sqlplus from a C: folder (with my script in that folder), the current drive and directory remains unchanged and is not changed to C:WINDOWS.
C:Other>sqlplus user/pwd@sid
SQL> host cd
C:Other
SQL> @myscript.sql
(myscript runs)
Once we exit from sqlplus, this original current directory is restored (I guess sqlplus acts as a shell to preserve the underlying environment).
So my question is, how can I run sqlplus without having my current directory changed to C:WINDOWS (other than always running sqlplus from a C: directory)?
Has this change of behaviour (if always used to retain the current directory when starting sqlplus) come about from a recent update or patch (and if so, which one)?
Is it possible to change the current drive or directory from within sqlplus (for example doing something like host cd /D D:Folder
? (I’m assuming not as the host command itself appears to run as a shell that is immediately discarded).