I am trying to execute an sql script with powershell and sqlplus but I am getting inconsistent behavior.
I have a file query.sql. It has one line as :
SELECT * FROM mytable;
When I execute it with
PS C:\MyScripts> sqlplus {myUser}@{myConnection} "@query.sql"
The command returns the results correctly. But when I try
PS C:\MyScripts> "SELECT * FROM mytable;" | sqlplus {myUser}@{myConnection}
the sqlplus returns and error:
SQL> SP2-0734: unknown command beginning "SELECT ..." - rest of line ignored.
How can this happen and what does it mean?
I expect that the same command can be executed with both of the mentioned methods - standard input from PowerShell string and input from a .sql file.