【问题标题】:Result of query set into variable - powershell查询结果设置为变量 - powershell
【发布时间】:2015-10-14 09:42:19
【问题描述】:

我需要将查询结果放入变量中 - 我正在使用 powershell 和 sqlplus。我的想法很简单,当然行不通。有什么简单的方法吗?

我尝试过这样的事情:

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

$result = sqlplus test/test132@server01 $query

$result

【问题讨论】:

  • $result = Invoke-Expression "sqlplus test/test132@server01 $query" 有帮助吗?
  • 不幸的是没有..这告诉我'使用'..
  • 那么它至少在捕获命令输出,只是听起来命令没有正确执行。尝试将$query 放在单引号中
  • 我试过这个 - Invoke-Expression "sqlplus test/test132@server 'select name from name'" -> 使用结果相同

标签: oracle powershell sqlplus


【解决方案1】:

你可以试试这样的:

$Command.CommandText = "select column1 from table1"

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

只要适应你自己的参数就行了

【讨论】:

    猜你喜欢
    • 2021-02-11
    • 2012-06-28
    • 1970-01-01
    • 2012-08-20
    • 2014-06-03
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多