Thursday, 1 August 2019

Heredoc for DOS/Powershell (multiple commands to SQL*Plus)

Hi, I do this all the time in Linux, sending multiple commands to a programme...
sqlplus / as sysdba <<!
shutdown immediate
startup
@?/rdbms/admin/utlrp
!
It's called heredoc but trying to do the same in DOS was slightly different and took a while to figure out...
( echo shutdown immediate
echo startup
echo @?/rdbms/admin/utlrp
) | sqlplus / as sysdba
To explain the () allows me to enter a number of lines before executing them and returning me to the command prompt.

I need these new lines as SQL*Plus expects them as delimiters to seperate commands.

So the above commands echo's a number of commands and pipes the results to SQL*Plus.

To embed brackets you need to escape the bracket using ^^^( and ^^^) like this...
( echo shutdown immediate
echo Starting database ^^^(normally^^^)
echo startup
echo @?/rdbms/admin/utlrp
) | sqlplus / as sysdba
To do the same in PowerShell do the following...
@' echo shutdown immediate
echo startup
echo @?/rdbms/admin/utlrp
'@ | sqlplus / as sysdba
The closing '@ must be at the beginning of the line with no preceeding spaces, otherwise it will fail.

No comments:

Post a comment

Oracle CPU downloader

Every quarter I have to go through and download numerous patches for the Oracle CPU (Critical Patch Update). You have to view the CPU docume...