ORA-06550: 在 ASP.NET 中调用 oracle 包内的函数时,参数数量或类型错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11419722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA-06550: Wrong number or type of arguments error when calling a function inside an oracle package in ASP.NET
提问by shresthaal
I have a function inside an oracle package called TEST in an Oracle 10g database
我在 Oracle 10g 数据库中名为 TEST 的 oracle 包中有一个函数
FUNCTION GetEname(P_ename IN VARCHAR2) RETURN VARCHAR2 AS
retVal VARCHAR2(10);
BEGIN
retVal := SUBSTR(P_ename, 3, INSTR(P_ename, ':', 1, 2) - 3);
RETURN RetVal;
END GetEntDefIEIDFromEname;
I have created an ASP.net page and I have the following code in the page_load:
我创建了一个 ASP.net 页面,并且在 page_load 中有以下代码:
String strResult = "";
try
{
oracleConn.ConnectionString = ConfigurationManager.ConnectionStrings["OracleDatabase"].ConnectionString;
oracleConn.Open();
OracleCommand orclCmnd = new OracleCommand();
orclCmnd.Connection = oracleConn;
orclCmnd.CommandText = "TEST.GetEname";
orclCmnd.CommandType = CommandType.StoredProcedure;
OracleParameter ename = new OracleParameter();
ename.ParameterName = "ename";
ename.OracleType = OracleType.VarChar;
ename.Direction = ParameterDirection.Input;
ename.Value = "0:490330";
orclCmnd.Parameters.Add(ename);
strResult = (String)orclCmnd.ExecuteOracleScalar();
oracleConn.Close();
oracleConn.Dispose();
lbl1.Text = "Result of " + strResult;
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.ToString());
oracleConn.Close();
}
When I run the code I get the following error message:
当我运行代码时,我收到以下错误消息:
"ORA-06550: line 1, column 7:\nPLS-00306: wrong number or types of arguments in call to 'GETENAME'\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored\n"} System.Exception {System.Data.OracleClient.OracleException}
"ORA-06550:第 1 行,第 7 列:\nPLS-00306:调用 'GETENAME' 时参数的数量或类型错误\nORA-06550:第 1 行,第 7 列:\nPL/SQL:忽略语句\n"} System.Exception {System.Data.OracleClient.OracleException}
回答by D Stanley
You're using a different name for the parameter in your code. Try changing
您在代码中为参数使用了不同的名称。尝试改变
ename.ParameterName = "ename";
to
到
ename.ParameterName = "P_ename";
ALSO
还
You need to add a parameter for the output value:
您需要为输出值添加一个参数:
OracleParameter result = new OracleParameter();
result.OracleType = OracleType.VarChar;
result.Direction = ParameterDirection.ReturnValue;
orclCmnd.Parameters.Add(result);
And get the value from the parameter after calling the function with ExecuteNonQuery:
并在使用 ExecuteNonQuery 调用函数后从参数中获取值:
orclCmnd.ExecuteNonQuery();
strResult = result.Value.ToString();