2015-10-14 34 views
1

我需要查詢結果到變量中 - 我正在使用powershell和sqlplus。我的想法很簡單,當然不起作用。有沒有簡單的方法?查詢設置爲變量的結果 - powershell

我已經試過這樣的事情:

$query= 'select name from cars where id = 56382301' 

$result = sqlplus test/[email protected] $query 

$result 
+0

是否'$結果= Invoke-表達式「sqlplus test/test132 @ server01 $ query」'help? – arco444

+0

不幸的是,這不僅顯示了我'使用'.. – charles

+0

然後,它至少捕獲命令輸出,它只是聽起來像命令沒有正確執行。嘗試把'$ query'放在單引號中 – arco444

回答

1

你可以嘗試這樣的事情:

$Command.CommandText = "select column1 from table1" 

$Reader = $Command.ExecuteReader() 
$column1 = $Reader.GetValue(0) 

只是使其適應自己的參數