Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

C# - get return value from function

LuckyLuke82Aug 24 2017 — edited Aug 24 2017

Hi, I have this function placed in Oracle DB:

CREATE OR REPLACE FUNCTION CONN_LC

(APP_IN IN varchar2)

RETURN varchar

IS

Has_value varchar(256);

cursor c1 is

SELECT Myfield

FROM MyTable

WHERE Name= APP_IN;

BEGIN

   open c1;

   fetch c1 into Has_value;

    if c1%notfound then

  

      Has_value := 0;

  

    else

  

      Has_value := 1;

 

   end if;

 

   close c1;

 

   RETURN Has_value;

   

END  CONN_LC;

/

Function returns me correct results in Oracle . It checks If certain field in table is empty and returns "0" or "1".

Now my problem is that I can't get the function value from C#. This is what I tried:

cmd.CommandText = "CONN_LC";

cmb.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new OracleParameter("tt", OracleDbType.Varchar2,256,ParameterDirection.ReturnValue));

cmd.Parameters.Add(new OracleParameter("APP_IN", OracleDbType.Varchar2,combobox1.Text, ParameterDirection.Input));

cmd.ExecuteNonQuery();

string result = cmd.Parameters["tt"].Value.ToString();

                    if (result=="1")

                    {

                       //....

                       //...

                    }

I've tried a lot of things, but nothing get's the value form Oracle. What am I doing wrong ??

P.S.: I'm getting error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small, ORA-06512: at line 1

This post has been answered by LuckyLuke82 on Aug 24 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 21 2017
Added on Aug 24 2017
2 comments
8,533 views