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!

How to check for null value of output parameter?

MorvenDec 8 2011 — edited Jan 10 2012
Hi guys, I get a test procedure with 2 output parameters and do nothing:
CREATE OR REPLACE PACKAGE BODY p_parameters_test AS 
  PROCEDURE p_null_output_basetype(p1 OUT NUMBER,p2 OUT VARCHAR2) 
  AS
  BEGIN
    DBMS_OUTPUT.PUT_LINE('DO NOTHING');
  END p_null_output_basetype;
END;
And I have below C# code:
cmd.CommandText = "p_parameters_test.p_null_output_basetype";
OracleParameter p1 = new OracleParameter("p1", OracleDbType.Decimal, System.Data.ParameterDirection.Output);
OracleParameter p2 = new OracleParameter("p2", OracleDbType.Varchar2, System.Data.ParameterDirection.Output);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
            
try
{
    conn.Open();
    cmd.ExecuteNonQuery();
    //
    if (p1.Value==null)
    {
        Console.WriteLine("p1.Value==null");
    }
    else if (Convert.IsDBNull(p1.Value))
    {
        Console.WriteLine("Convert.IsDBNull(p1.Value)");
    }
    else
    {
        Console.WriteLine("p1 else "+p1.Value);
    }
    //
    if (p2.Value==null)
    {
        Console.WriteLine("p2.Value==null");
    }
    else if (Convert.IsDBNull(p2.Value))
    {
        Console.WriteLine("Convert.IsDBNull(p2.Value)");
    }
    else
    {
        Console.WriteLine("p2 else "+p2.Value);
    }
    //
    Console.WriteLine("finished");
}
catch......
The output of it is:
p1 else null
p2 else null

Does anyone have any idea why it always goes to the 'else' of the condition-branching, and how can I check if the output parameter is null?

Thanks in advance.
This post has been answered by 900677 on Jan 3 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 7 2012
Added on Dec 8 2011
3 comments
13,663 views