0

I want to run oracle query through PowerShell. Single line query is running fine with no error. But now I have to run multi-line query.

set lines 400
select name,host_name,status,open_mode,to_char(startup_time,'DD-Mon-yy HH24:MI:SS') STARTUP_TIME from v$inst,v$db;

I tried this

$sql=@(
"set lines 400
select name,host_name,status,open_mode,to_char(startup_time,'DD-Mon-yy HH24:MI:SS') STARTUP_TIME from v`$inst,v`$db"
)

And multiple options but it is giving me error ORA-00922.

I am using ODP.net in PowerShell.

Please advise.

Update:

If I run this query in oracle(without PowerShell) then it is working fine.

1 Answer 1

1

Your $SQL Variable is an Array with only one line:

$sql.Count
1

Try create it in that way:

$sql = @()
$sql += 'set lines 400'
$sql += 'select name,host_name,status,open_mode,to_char(startup_time,''DD-Mon-yy HH24:MI:SS'') STARTUP_TIME from v`$inst,v`$db"'

Important Note:

When using 'Quotes' inside the string you should add ''Dobule Quoutes'' otherwise it will be illegal - like this: ''DD-Mon-yy HH24:MI:SS''

Sign up to request clarification or add additional context in comments.

6 Comments

Let me try. Voted up. Now i am getting this error. "ORA-00900: invalid SQL statement"
ORA-00900 was due to syntax error. Now I follow the same instruction provided by you and it is giving me ORA-00922. After this line $reader=$command.ExecuteReader()
If i simply check the $sql value then it is giving me query with no error
Script is not going till there (foreach or Outline). It is giving me error at executereader(). However, I tried to run this code $sql=@() $sql += 'set lines 200' $sql += "select Username,User_ID from dba_users" but it is also giving me same error.
If i simply run this $sql= "select Username,User_ID from dba_users" then it is giving me output.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.