No Clean Feed - Stop Internet Censorship in Australia

HOWTO: Determine the source of an Oracle view using ADO.NET

If you were trying to determine the source of a particular view using a query tool, you'd do something like this:

	SELECT TEXT FROM USER_VIEWS WHERE VIEW_NAME = 'MY_VIEW';

However, when you attempt to run the same query through ADO.NET, you'll notice that the TEXT column returned is empty. There is a trick to this: close inspection of the USER_VIEWS table will show that the type of the TEXT column is LONG.

The reason for the empty text is that LONG columns are truncated during return to a length specified in the ADO.NET command object, and the default truncation length is ... zero. The fix is to set the InitalLONGFetchSize property before executing the command:

	OracleCommand command = new OracleCommand(
"SELECT TEXT FROM USER_VIEWS WHERE VIEW_NAME = 'MY_VIEW'", connection);
command.InitialLONGFetchSize = int.MaxValue;

StringBuilder sb = new StringBuilder();
using (OracleDataReader resultReader = command.ExecuteReader())
{
while (resultReader.Read())
{
string result = resultReader.GetValue(0).ToString();
sb.Append(result.Replace("\n", "\r\n"));
}
}

return sb.ToString();

And voilà! You have the source of the view.