I wan to call oracle database function I tried this but i am getting error

ORA-06550: line 1, column 7: PLS-00221: 'F_GET_DESC' is not a procedure or is undefined ORA-06550: line 1, column 7: PL/SQL: Statement ignored

public void Get_Desc()
{
    string oradb = "Data Source=source;User Id=myuser;Password=ss;";

    string CommandStr = "F_Get_Desc()";

    using (OracleConnection conn = new OracleConnection(oradb))
    using (OracleCommand cmd = new OracleCommand(CommandStr, conn))
    {
        conn.Open();
        cmd.CommandType = CommandType.StoredProcedure;

        OracleParameter pDesc = new OracleParameter("pDesc", OracleDbType.Varchar2,128);
        pOfficeDesc.Direction = ParameterDirection.Input;
        pOfficeDesc.Value = Current_code.ToString();
        cmd.Parameters.Add(pDesc);
        cmd.ExecuteNonQuery();

        MessageBox.Show(pDesc.Value.ToString(););
    }
}

Recommended Answers

All 3 Replies

You said that F_Get_Desc is a function, but you're trying to call it as an stored procedure.

Try using CommandType.Text instead.

I tried but i got an error says ORA-00900: invalid SQL statement
and i dont think that is the reason couse i used same way to call another function
and its work fine the only difference that the F_Get_Desc has in paramerter as u can see below

CREATE OR REPLACE FUNCTION Schema.F_Get_Desc(P_CODE VARCHAR2)
RETURN VARCHAR2
IS
  v_DESC VARCHAR2(64);

BEGIN
 IF P_CODE IS NULL THEN
  RETURN('');
 END IF;

 SELECT NAME_dsec
 INTO   V_DESC
 FROM   My_table
 WHERE  CODE = P_CODE;

 RETURN(V_DESC);
END;
/

AleMonteiro is correct, it should be CommandType.Text. You need to modify your CommandStr variable to be valid SQL. Something like string CommandStr = "SELECT F_Get_Desc(@PDesc)"; and then you reference the parameter as @PDesc like so:

OracleParameter pDesc = new OracleParameter("@PDesc", OracleDbType.Varchar2,128);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.