1

The title says it all really, I have been trying to execute a SQL Oracle script through PowerShell, but it is not working. I am not getting an error, it just says 'running script/selection' at the bottom right hand corner. However I do not think it is correctly connecting to Oracle.

Please see the code in the .ps1 file:

sqlplus Username\Password "@C:\Users\...\script1.sql"

In the sql script there is:

CREATE TABLE DEPT 
(
  DEPTNO VARCHAR2(20) 
, DNAME VARCHAR2(20) 
, LOC VARCHAR2(20) 
);
ploutch
  • 1,204
  • 10
  • 12
  • The link mentioned here explains everything clearly. Just folow it. https://www.simple-talk.com/sql/sql-tools/using-powershell-to-generate-table-creation-scripts/ – XING Nov 15 '16 at 14:29
  • There are a number of questions on this site which are similar. Have you seen these questions, http://stackoverflow.com/questions/9627225/execute-sqlplus-from-powershell, http://stackoverflow.com/questions/24682465/how-to-run-a-sql-plus-script-in-powershell – Patrick Bacon Nov 15 '16 at 14:45
  • I had see these links before, but thank you for posting: The solution which I later discovered was: `sqlplus -s database/password@$pathtoscript` – Chris Izzard Nov 16 '16 at 14:27

1 Answers1

0

You can use the following

sqlplus <<UserName>>/<<Password>>@<<Database>> @"<<ScriptFilePath>>"

Database should be tnsnames.ora entry. You can use the following directly.

Joshan George
  • 668
  • 1
  • 7
  • 14