首先,我来自阿根廷,抱歉英语很差!
我在Visual.NET 2010中工作,我正在尝试调用Oracle包中的函数,但是我收到了这个错误:
PLS-00306:调用'FN_FINDPRONOSTICO'时参数的数量或类型错误
这是包装定义:
create or replace
PACKAGE PKG_HOME AS
TYPE CR_ESTACIONREFERENCIA IS REF CURSOR;
TYPE CR_PRONOSTICO IS REF CURSOR;
TYPE CR_ALERTA IS REF CURSOR;
TYPE CR_ESTADIOSPREDOMINANTESZONA IS REF CURSOR;
TYPE CR_VARIEDADES IS REF CURSOR;
--FUNCTIONS
FUNCTION FN_FINDESTACIONREFERENCIA(PR_IDZONAFENO IN NUMERIC) RETURN CR_ESTACIONREFERENCIA;
FUNCTION FN_FINDPRONOSTICO(PR_IDESTACION IN NUMERIC) RETURN CR_PRONOSTICO;
FUNCTION FN_FINDALERTAMETEO(PR_IDESTACION IN NUMERIC) RETURN CR_ALERTA;
FUNCTION FN_FINDALERTAPLAGA(PR_IDZONAFENO IN NUMERIC) RETURN CR_ALERTA;
FUNCTION FN_FINDALERTAENFERMEDAD(PR_IDZONAFENO IN NUMERIC) RETURN CR_ALERTA;
PROCEDURE SP_ESTFENOPREDZONAVAR(pFechaDesde IN DATE, pFechaHasta IN DATE,pIdZona IN NUMBER ,pIdVariedad IN NUMBER);
FUNCTION FN_ESTADIOSFENOPREDZONA(pIdZona IN NUMBER) RETURN CR_ESTADIOSPREDOMINANTESZONA;
END;
这是VB.NET中的代码
Dim cmd As New OracleCommand("FRUTIC.PKG_HOME.FN_FINDPRONOSTICO", OraConn)
cmd.CommandType = CommandType.StoredProcedure
cmd.BindByName = True
Dim oparam0 As OracleParameter = cmd.Parameters.Add("PR_IDESTACION", OracleDbType.Int64)
oparam0.Value = 65
oparam0.Direction = ParameterDirection.Input
Dim oparam1 As OracleParameter = cmd.Parameters.Add("CR_PRONOSTICO", OracleDbType.RefCursor)
oparam1.Direction = ParameterDirection.Output
Dim reader As OracleDataReader
reader = cmd.ExecuteReader()
Do While reader.Read()
Dim obj As Object
obj = reader.GetValue(0)
Loop
如果我在Oracle SQL Developer中运行此SQL语句(SELECT FRUTIC.PKG_HOME.FN_FINDPRONOSTICO(65)FROM DUAL),它会正确返回结果。
哪里可能是问题?
非常感谢您提前! 来自阿根廷的问候,卢卡斯
答案 0 :(得分:1)
这是错误的:
Dim oparam1 As OracleParameter = cmd.Parameters.Add("CR_PRONOSTICO", OracleDbType.RefCursor)
oparam1.Direction = ParameterDirection.Output
一定是这样的:
Dim oparam1 As OracleParameter = cmd.Parameters.Add("CR_PRONOSTICO", OracleDbType.RefCursor)
oparam1.Direction = ParameterDirection.ReturnValue
答案 1 :(得分:0)
也许您必须使用“ReturnValue”而不是“Output”。这样做:
Dim oparam0 As OracleParameter = cmd.Parameters.Add("PR_IDESTACION", OracleDbType.Int64)
oparam0.Value = 65
oparam0.Direction = ParameterDirection.Input
Dim oparam1 As OracleParameter = cmd.Parameters.Add("CR_PRONOSTICO", OracleDbType.RefCursor)
oparam1.Direction = ParameterDirection.**ReturnValue**