我在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;
我创建了一个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();
}
当我运行代码时,我收到以下错误消息:
“ORA-06550:第1行第7列:\ nPLS-00306:错误的数量或类型 调用'GETENAME'时的参数\ nORA-06550:第1行第7列:\ nPL / SQL: 语句被忽略\ n“} System.Exception {System.Data.OracleClient.OracleException}
答案 0 :(得分:6)
您在代码中使用了不同的参数名称。尝试更改
ename.ParameterName = "ename";
到
ename.ParameterName = "P_ename";
ALSO
您需要为输出值添加参数:
OracleParameter result = new OracleParameter();
result.OracleType = OracleType.VarChar;
result.Direction = ParameterDirection.ReturnValue;
orclCmnd.Parameters.Add(result);
使用ExecuteNonQuery调用函数后从参数中获取值:
orclCmnd.ExecuteNonQuery();
strResult = result.Value.ToString();