Connecting to Oracle via SQLplus and outputing to .csv file RRS feed

  • Question

  • Hello,

    I have issue outputing my query into .csv file. 

    This is my script 

    $sqlQuery = 
      select name from v`$database;
    $username = "user1"
    $password = "password"
    $tnsalias = "db_name"
    $ds = New-Object system.Data.DataSet
    $outputfile = "C:\Users\user1\output3.csv"
    $sqlQuery | sqlplus $username/$password@$tnsalias $ds.Tables[0] | SELECT name | Export-CSV $outputfile -NoTypeInformation -append 

    I do not get actual output, I only get column name in this case "name". 

    How can I get output, it should show database name "db_name". 

    • Edited by Linkem55 Tuesday, September 17, 2019 8:27 PM
    Tuesday, September 17, 2019 8:26 PM

All replies

  • For instructions on using SQL and Oracle please post in an Oracle forum. SQLPLUS is an Oracle only utility and is not part of Windows or supported by Microsoft.

    Hint:  If your SQL only asks for "name" then that is all you will get.

    SQLPLUS cannot load a dataset. It only returns text. Contact Oracle for help using this utility.


    Tuesday, September 17, 2019 11:00 PM