从C#:PLS-00306调用包函数

时间:2009-10-02 13:26:56

标签: c# oracle function

我正在尝试从C#调用Oracle包函数,但我一直收到同样的错误:PLS-00306:调用'F_CTCPREPAREP151HEADER'时参数的数量或类型错误。

这是包中的函数声明:

function f_CtcPrepareP151Header
(
as_codjal in varchar2/*,
ad_datdoc in varchar2,
as_codfnr in varchar2,
ad_dtfafo in varchar2,
as_reffnr in varchar2,
as_vcs in varchar2,
as_devfnr in varchar2,
ad_datech in varchar2,
al_totdev in number,
al_tvadev in number,
al_tvafac in number,
as_codtva in varchar2,
as_libele in varchar2,
as_xlogcr in varchar2,
as_typesc in varchar2,
al_pouesc in number,
al_jouesc in number,
al_docrec in number,
as_msglan in varchar2*/,
rs_msgerr in out varchar2
)
return integer;

这是包体中的函数声明:

function f_CtcPrepareP151Header
(
as_codjal in varchar2/*,
ad_datdoc in varchar2,
as_codfnr in varchar2,
ad_dtfafo in varchar2,
as_reffnr in varchar2,
as_vcs in varchar2,
as_devfnr in varchar2,
ad_datech in varchar2,
al_totdev in number,
al_tvadev in number,
al_tvafac in number,
as_codtva in varchar2, -- tvaspe
as_libele in varchar2, -- numero de bon de commande (texte libre)
as_xlogcr in varchar2,
as_typesc in varchar2,
al_pouesc in number,
al_jouesc in number,
al_docrec in number, -- numero de document Recomatics (ctcd15.des001)
as_msglan in varchar2*/,
rs_msgerr in out varchar2
)
return integer
is
begin
/*rs_msgerr := 'test';*/
return 1;
end f_CtcPrepareP151Header;

这就是我调用函数的方式:

OleDbCommand l_oCmd1 = new OleDbCommand("PKG_TEMREC.f_ctcPrepareP151Header", l_oConContractor);
l_oCmd1.CommandType = CommandType.StoredProcedure;

l_strExtraInfo = "f_ctcPrepareP151Header : Create return parameter";
OleDbParameter l_RetValue1 = l_oCmd1.Parameters.Add("RetVal", OleDbType.Integer);
l_RetValue1.Direction = ParameterDirection.ReturnValue;

l_strExtraInfo = "f_ctcPrepareP151Header : Create journal parameter";
OleDbParameter l_oJournalPar1 = new OleDbParameter("as_codjal", OleDbType.VarChar);
l_oJournalPar1.Direction = ParameterDirection.Input;
l_oJournalPar1.Value = l_strJournal;
l_oJournalPar1.Size = l_strJournal.Length;
l_oCmd1.Parameters.Add(l_oJournalPar1);

l_strExtraInfo = "f_ctcPrepareP151Header : Create message parameter";
OleDbParameter l_oErrMsgPar1 = l_oCmd1.Parameters.Add("rs_msgerr", OleDbType.VarChar);
l_oErrMsgPar1.Direction = ParameterDirection.InputOutput;
l_oErrMsgPar1.Size = 4000;
l_oErrMsgPar1.Value = new String(' ', 4000);

try
{
ExecuteFunction(l_oCmd1, l_oConContractor, l_oTrans, l_RetValue1, l_oErrMsgPar1, "f_ctcPrepareP151Header");
}
catch (Exception e)
{
throw new Exception("Error while preparing invoice header: " + e.Message);
}

ExecuteFunction函数如下:

private void ExecuteFunction(OleDbCommand oCmd, OleDbConnection oConn, OleDbTransaction oTrans, OleDbParameter oRetValue, OleDbParameter oErrMsg, string strFunctionName)
{
try
{
oCmd.Transaction = oTrans;
oCmd.ExecuteNonQuery();

if ((oRetValue != null) && (oRetValue.Value != null))
{
int iOutputValue = Convert.ToInt32(oRetValue.Value.ToString());
if (iOutputValue < 0)
{
throw new Exception(oErrMsg.Value.ToString());
}
}
}
catch (Exception e)
{
string l_strMsg = string.Format("Exception in procedure PKG_TEMREC." + strFunctionName + " - " + e.Message + "(" + oCmd.CommandText + ")");
throw new Exception(l_strMsg);
}
}

有谁能告诉我我做错了什么?我知道我在函数声明中注释了很多参数,但这是出于测试目的。

谢谢,

克里斯托弗。

1 个答案:

答案 0 :(得分:0)

也许是returnvalue参数?对于Oracle整数,也许OleDbType.Integer是小到的。 Oracle整数可能很长。长度超过32位或64位可以保持。