如何使用PowerShell拆分每一行

时间:2014-11-07 08:27:33

标签: oracle powershell

我正在尝试使用PowerShell将一个表从一个数据库插入另一个(行)。我已经知道如何获取数据,但当我尝试将其插入新表时,我得到一个错误,即字符串太长(我认为这意味着我试图将所有数据放入一个新行)。我已经在网上搜索了答案。我唯一能找到的是命令-split但是我需要分解一些东西,数据只是数字。

您将在下面找到该脚本。

   $query = “SELECT ZAMNIEUW.MACHINENAME  FROM ZAMNIEUW WHERE MACHINENAME  not in (SELECT PATCHGROEPEN.MACHINENAME FROM PATCHGROEPEN ) "
                $command = $con.CreateCommand()
                $command.CommandText = $query
                $result = $command.ExecuteReader()
                $table = new-object “System.Data.DataTable”
                $table.Load($result)
                $format = @{Expression={$_.WAARDE_PCNAME};Label=”ID”;width=20}


   echo $table.MACHINENAME


                 $table| foreach {

$qu= " INSERT into  TESTZEN (MACHINENAME) VALUES('$table')"
$cmd = $con.CreateCommand()
$cmd.CommandText = $qu
$cmd.ExecuteNonQuery() |out-null     

}

1 个答案:

答案 0 :(得分:0)

显然oracle确实使用了一些东西来分割每一行(;)

以下代码

$query = “SELECT ZAMNIEUW.MACHINENAME  FROM ZAMNIEUW WHERE MACHINENAME  not in (SELECT PATCHGROEPEN.MACHINENAME FROM PATCHGROEPEN ) "
                    $command = $con.CreateCommand()
                    $command.CommandText = $query
                    $result = $command.ExecuteReader()
                    $table = new-object “System.Data.DataTable”
                    $table.Load($result)
                    $format = @{Expression={$_.WAARDE_PCNAME};Label=”ID”;width=20}


              $tables =echo $table.MACHINENAME


                     $tables| foreach {

                                           $tables = $_ -split ';'
                                            $qu= " INSERT into  TESTZEN (MACHINENAME) VALUES('$tables')"
                                            $cmd = $con.CreateCommand()
                                            $cmd.CommandText = $qu
                                            $cmd.ExecuteNonQuery() |out-null     







       }