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
私はこれを機能させることができません!助けてください!