When I run the following SQL in Oracle, the column default value is reported correctly ('Test'). When I run the same SQL in .NET, the reported default value is NULL:
SELECT column_name, data_default FROM user_tab_columns WHERE table_name='MYTABLENAME'
The column in question is Varchar2. I also tested a number column - same problem.
The database version is Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
The .NET connector is ODP.NET
The operating system is Windows 7 / 64
I get the same result (NULL) from all_tab_columns
.NET Code:
Dim provider As DbProviderFactory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client")
Using connection As DbConnection = provider.CreateConnection
connection.ConnectionString = "Data Source=localhost; User Id=userid; Password=password"
connection.Open
Using dt As New DataTable
Using command As DbCommand = provider.CreateCommand
command.CommandText = "SELECT column_name, data_default FROM user_tab_columns WHERE table_name='MYTABLENAME'"
command.Connection = connection
Using da As DbDataAdapter = provider.CreateDataAdapter
da.SelectCommand = command
da.Fill(dt)
End Using
End Using
For Each row As DataRow in dt.Rows
Response.Write(row("COLUMN_NAME") & " " & row("DATA_DEFAULT") & "<br>")
Next
End Using
End Using
Using command. I work mostly with C# so my VB.NET is terrible, but in C# you're supposed to instantiate the variable in theusingconstruct - you shouldn't instantiate it ahead of time and supply the instance variable toUsingas you've done. A couple of things to try for diagnostic purposes: (1) see what happens if you change theWHEREclause of the query fromWHERE table_name='MYTABLENAME'toWHERE ROWNUM < 10. (2) what happens if you get rid of theUsing commandwrapper?