0

Oracle 挿入用のパラメーターのハッシュ テーブルを渡しています。ハッシュ テーブルの値の内容は配列です。このエラーが発生し続けます:

Exception setting "Value": "Value does not fall within the expected range."

配列バインディングを使用して値を追加しようとすると。有効なコマンド オブジェクトがあり、ArrayBindCount を正しい値に設定しました。ここに私が使用しているコードと出力があります。これはうまくいくはずです!$parameterValues 変数には、渡すハッシュ テーブルが含まれていることに注意してください。

$cmdObject = New-Object Oracle.DataAccess.Client.OracleCommand($sqlStatement,$connectionObject)
 $cmdObject.BindByName = $true

if($parameterValues)
 {
  ForEach($p in $parameterValues.GetEnumerator())
  {
   $cmdObject.ArrayBindCount = $p.Value.Count
   Write-Host ("ParameterName = ""{0}"" type = {1} Parameter Value Type = {2} Count = {3}" -f $p.Key, $p.Key.GetType().FullName, $p.Value.GetType().FullName, $p.Value.Count)
   $oraParam = New-Object Oracle.DataAccess.Client.OracleParameter
   $oraParam.ParameterName = $p.Key
   $oraParam.Value = $p.Value
   $cmdObject.Parameters.Add($oraParam) | Out-Null
  }

  Write-Host("Number of parameters in `$cmdObject.Parameters = {0}" -f $cmdObject.Parameters.Count)

Write-Host ("Value of `$cmdObject.ArrayBindCount = {0}" -f $cmdObject.ArrayBindCount)

これが私が得ている出力とエラーです:

    Value of $cmdObject.CommandText =  insert into regions (region_id, region_name) values (:REGION_ID, :REGION_NAME)
ParameterName = "REGION_NAME" type = System.String Parameter Value Type = System.String[] Count = 4
    Exception setting "Value": "Value does not fall within the expected range."
    At C:\Users\areum\Downloads\wd\Scratch\HelloPSWorld_functions.ps1:1615 char:4
    +    $oraParam.Value = $p.Value
    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
        + FullyQualifiedErrorId : ExceptionWhenSetting

    ParameterName = "REGION_ID" type = System.String Parameter Value Type = System.Int32[] Count = 4
    Exception setting "Value": "Value does not fall within the expected range."
    At C:\Users\areum\Downloads\wd\Scratch\HelloPSWorld_functions.ps1:1615 char:4
    +    $oraParam.Value = $p.Value
    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
        + FullyQualifiedErrorId : ExceptionWhenSetting

    Number of parameters in $cmdObject.Parameters = 2
    Value of $cmdObject.ArrayBindCount = 4

私はこれを機能させることができません!助けてください!

4

1 に答える 1

0

その例外はOracleから来ています。文字列ではなく、intのみを指定できるようです。値が int に変換できる文字列だった場合は、[int]$p.Value を使用します。それ以外の場合は、古い学校の列挙型 (適切な構造ではなく単なる数値) である可能性があります。その場合は、その列挙型から int への直接変換を調べてください (特定の文字列をオンラインで検索してみてください。実際の値に関するドキュメントが見つかるはずです)。

物語の教訓は次のとおりです。

PowerShell で例外が発生した場合は、注意してください。PowerShell レイヤーから発生することはめったになく、通常は表面のすぐ下にある .NET から発生します。

于 2013-09-26T21:18:59.520 に答える