I use the call operator, &
, as Keith Hill has suggested with the question, How to run an EXE file in PowerShell with parameters with spaces and quotes.
& 'pathsqlplus.exe' 'system/password@dbase as sysdba'
I placed the username, password in quotes due to the spaces.
To start a script, I add another parameter as follows:
& 'pathsqlplus.exe' 'system/password@dbase as sysdba' '@my_script.sql'
If you are receiving the ORA-12154 error, and you know that other users have
established connections (which implies that the database listener is running
properly); I would then examine if SQL*Plus can find my tnsname file.
My first task would be to see if I can tnsping as follows in Windows cmd.exe:
tnsping orcl
It will confirm that a connection can (or can not be established).
If it cannot, I would check to see if the environment variable, ORACLE_HOME,
is set. SQL*Plus uses this to find tnsname.ora file.
If it is not set, I would execute this statement in PowerShell (to establish
this environment variable):
[Environment]::SetEnvironmentVariable("ORACLE_HOME", "C:appAdministratorproduct11.2.0client_1" , "User")
Next, I would retry to tnsping (identified above).
Once successful, I would re-try to execute the script running command above.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…