LINK 1

Using Regular Expressions With Oracle Database

A little old but I can’t find this particular guide, Oracle Database Application Developer’s Guide - Fundamentals, for Oracle 11g.

posted 1 month ago

TEXT

Oracle 11g ODP.NET Null String Issues

I ran into a problem today returning a NULL field from the database to a ASP.NET webform. I’ve been using Oracle with C# for quite a while now and this is the first time I have run into this problem. Instead of displaying nothing in the browser, the word “null” was showing up when selecting from a NULL field in the database. For example,

SELECT field_name INTO variable FROM table_name WHERE id = 1;

If field_name had no value then “null” was displayed on the form instead of nothing. After some Googling and trying some different things with DBNull.Value, I finally came across a solution on Stack Overflow. There were 4 or 5 posts closely related to this problem but only one had a solution that worked for me, Oracle 11g odp.net driver issues with Null value.

Turns out, if you use OracleDbTypeEx instead of OracleDbType, when the value returns  it will recognize DBNull. I was previously using the following to define a parameter:

OracleParameter param_name = new OracleParameter("param_name", OracleDbType.Varchar2, 200);
param_name.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param_name);

param_name_out = param_name.Value.ToString();

Now I’m using the following, with the check for DBNull.Value.

OracleParameter param_name = new OracleParameter
{
	ParameterName = "param_name",
	OracleDbTypeEx = OracleDbType.Varchar2,
	Size = 200,
	Direction = ParameterDirection.Output
};
cmd.Parameters.Add(param_name);
			
if (param_name.Value != Convert.DBNull)
{
	param_name_out = param_name.Value.ToString();
}
else
{
	param_name_out = "";
}

Perhaps there’s another way to handle this, but this method worked for me. Thankful for Stack Overflow.

posted 1 month ago

ABOUT

Displaced Mississippian living in Dallas, Texas. Apple fanatic, sports nut, beer snob, devout atheist, & Ole Miss Rebel.

Connect with bigjim.