問題: パッケージ化されたストアド プロシージャを呼び出そうとしましたが、パラメーターの値によっては呼び出しが失敗します。
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1
手順の定義:
procedure DUP_EXACT (
SSN in VARCHAR2,
LASTNAME in VARCHAR2,
FIRSTNAME in VARCHAR2,
MASTERRECORD IN VARCHAR2 DEFAULT NULL,
C_Table out sp_cursor)
パラメータの作成:
For Each SearchParameter In SearchParameters
ValueParameter = New OracleParameter
ValueParameter.Direction = ParameterDirection.Input
ValueParameter.OracleDbType = OracleDbType.Varchar2
ValueParameter.ParameterName = SearchParameter.ParameterFieldName
If Not SearchParameter.TransformedFieldValue = Nothing Then
ValueParameter.Value = SearchParameter.TransformedFieldValue
Else
ValueParameter.Value = String.Empty
End If
ExactMatchSearchParameters.Add(ValueParameter)
Next
Dim MasterRecordParameter As New OracleParameter()
MasterRecordParameter.Direction = ParameterDirection.Input
MasterRecordParameter.OracleDbType = OracleDbType.Varchar2
MasterRecordParameter.ParameterName = "MASTERRECORD"
MasterRecordParameter.Value = DBNull.Value
ExactMatchSearchParameters.Add(MasterRecordParameter)
Dim TableParameter As New OracleParameter
TableParameter.ParameterName = "C_Table"
TableParameter.OracleDbType = OracleDbType.RefCursor
TableParameter.Direction = ParameterDirection.Output
ExactMatchSearchParameters.Add(TableParameter)
実行:
Using Command As OracleCommand =
New OracleCommand(
QualifiedProcedureName,
Me.Database.Connection)
Command.CommandType = CommandType.StoredProcedure
'Command.AddToStatementCache = False '
For Each Parameter In Parameters
Command.Parameters.Add(Parameter)
Next
Command.Connection.Open()
'Command.Connection.FlushCache() '
Using Reader As OracleDataReader = Command.ExecuteReader()
成功と失敗の例:
*** SUCCESS ***
[SSN]: "6#######0"
[LASTNAME]: "W_____x"
[FIRSTNAME]: "D______e"
[MASTERRECORD]: ""
[C_Table]: ""
*** FAILURE ***
[SSN]: "2#######_1"
[LASTNAME]: "C____n"
[FIRSTNAME]: "L___e"
[MASTERRECORD]: ""
[C_Table]: ""
*** FAILURE ***
[SSN]: "5#######5"
[LASTNAME]: "C_______s"
[FIRSTNAME]: "R_____o"
[MASTERRECORD]: ""
[C_Table]: ""
*** SUCCESS ***
[SSN]: "6#######0"
[LASTNAME]: "P___a"
[FIRSTNAME]: "N______r"
[MASTERRECORD]: ""
[C_Table]: ""
追加のテスト:
パラメータでODP.NETが実際にデータベースに送信しているものを確認するためにトレースを実行しようとしましたが、トレースファイルは意味のある情報を提供しませんでした(つまり、実際のパラメータ値)
TIME:2013/02/14-14:10:19:678
TID:231c
OpsSqlPrepare2():
SQL: Begin PACKAGE.DUP_EXACT(:v0, :v1, :v2, :v3, :v4); End;
パラメータ値の例:
?Command.Parameters(0)
{SSN}
ArrayBindSize: Nothing
ArrayBindStatus: Nothing
CollectionType: None {0}
DbType: String {16}
Direction: Input {1}
InvalidPrecision: 100
InvalidScale: 129
InvalidSize: -1
IsNullable: False
m_bOracleDbTypeExSet: False
m_bReturnDateTimeOffset: False
m_collRef: {Oracle.DataAccess.Client.OracleParameterCollection}
m_commandText: ""
m_direction: Input {1}
m_disposed: False
m_enumType: ORADBTYPE {4}
m_modified: False
m_oraDbType: Varchar2 {126}
m_paramName: "SSN"
m_paramPosOrName: ""
m_saveValue: Nothing
MaxScale: 127
MinScale: -84
Offset: 0
OracleDbType: Varchar2 {126}
OracleDbTypeEx: Varchar2 {126}
ParameterEnumType: ORADBTYPE {4}
ParameterName: "SSN"
Precision: 0
Scale: 0
Size: 0
SourceColumn: ""
SourceColumnNullMapping: False
SourceVersion: Current {512}
Status: Success {0}
UdtTypeName: ""
Value: "4#######0" {String}