Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to call a store procedure with output parameter as sys_refcursor through my C# code. But it is continuously giving me error saying "ORA-01036: illegal variable name/number"

I am using .NET framework 2.0 and System.Data.OracleClient for connecting Oracle database.

Is there anything that I am missing?

Thanks in advance

What I have tried:

I am writing here the C# and SP which I am using.

C# Code:


Public DataTable ExecuteReport(ReportFilters filterAttribute)
        {
            DataTable dtDetailedReport = new DataTable();
            using (OracleConnection conn = new OracleConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                OracleCommand cmd = new OracleCommand();
                cmd.Connection =conn;
                cmd.CommandText = "count_emp_by_dept";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("pin_no", OracleType.VarChar, 200).Value = filterAttribute.PIN;
                cmd.Parameters.Add("pResult ", OracleType.Cursor).Direction = ParameterDirection.Output;
                OracleDataAdapter adap =new OracleDataAdapter(cmd);
                adap.Fill(dtDetailedReport);
                conn.Close();
            }
            return dtDetailedReport;
        }


SP that I am using

Ceate or replace procedure count_emp_by_dept(pin_no Varchar2, pResult out sys_refcursor)
is
begin
  open pResult for 
 select pinname from TOC2_Test  where pin = pin_no;
end count_emp_by_dept;
Posted
Updated 8-Jun-18 10:49am

1 solution

Follow this: asp.net - Get oracle output parameter using OracleCommand - Stack Overflow[^]

Quote:
Make sure you set the SIZE property on the parameter before executing. With output parameters in Oracle, the specified size acts as a buffer. If the buffer isn't set, it is 0 so you don't get the value from the database.
C#
var param = Ocmd.Parameters.AddWithValue("OUTPUTParam","").Direction = ParameterDirection.Output;
param.Size = 255;
 
Share this answer
 
Comments
Nutan R 11-Jun-18 10:05am    
This does not work, and gives the same error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900