Search code examples
oracle-databasepowershellsqlplus

How to use a sql plus variable when calling a script?


I want to execute a powershell script from sqlplus which use a the variable a. As you can see if you execute this code, a isn't recognized. I would like this code to print 22, not a or :a

variable a varchar2;
a='22'
host powershell.exe echo :a
host powershell.exe echo a

:a

a


Solution

  • You could use a substitution variable:

    define a=22
    
    host powershell.exe echo &a
    

    If you already have the bind variable defined and populated by a process you don't want to change, you can set the substitution variable value using a dummy query and column ... new_value syntax.