问题: 尝试调用打包的存储过程,但调用失败取决于参数的值。
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实际上在参数中发送到数据库的内容,但是tracefiles没有提供任何有意义的信息(IE:实际参数值)
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}
答案 0 :(得分:2)
答案是Oracle 9.2.0.6.0中存在导致间歇性VARCHAR2绑定错误的错误。真棒。强>
This forum post finally gave me the answer:
此行为是一致的还是间歇性的?如果间歇,和 你的db是9206,你可能遇到以下rdbms错误:
Bug.4015165(74)REGRN SCALAR VARCHAR2在不同尺寸的箱子中 ORA-06502随机失败
应该通过修补数据库来解决。
我不知道为什么,但是ODP似乎比这更容易遇到这个错误 其他司机。
如果不是间歇性的,或者您使用的是当前的补丁级别 数据库,一个完整的测试用例可能是最好的。
干杯, 格雷格
快速检查确认我们所使用的版本受到影响:
select * from v$version;
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
PL/SQL Release 9.2.0.6.0 - Production
CORE 9.2.0.6.0 Production
TNS for 32-bit Windows: Version 9.2.0.6.0 - Production
NLSRTL Version 9.2.0.6.0 - Production
幸运的是我们的生产服务器是10g,所以我们最终将我们的开发服务器更新为10g,并且中提琴不再有问题。
回答路径:
答案 1 :(得分:1)
听起来可能很奇怪,但要确保oracle参数在查询中显示时添加。我过去曾经遇到过这个问题几次(通常是迁移到ODP.NET)