I have a function inside an oracle package called TEST in an Oracle 10g database
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:
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}
You’re using a different name for the parameter in your code. Try changing
to
ALSO
You need to add a parameter for the output value:
And get the value from the parameter after calling the function with ExecuteNonQuery: