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.



Recent comments
1 week 1 day ago
3 weeks 3 days ago
3 weeks 6 days ago
11 weeks 1 day ago
15 weeks 5 days ago
31 weeks 18 hours ago
31 weeks 23 hours ago
37 weeks 3 days ago
37 weeks 3 days ago
37 weeks 4 days ago