当我在 Oracle 中运行以下 SQL 时,会正确报告列默认值(“测试”)。当我在 .NET 中运行相同的 SQL 时,报告的默认值为 NULL:
SELECT column_name, data_default FROM user_tab_columns WHERE table_name='MYTABLENAME'
有问题的列是 Varchar2。我还测试了一个数字列 - 同样的问题。
数据库版本是 Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
.NET 连接器是 ODP.NET
操作系统是 Windows 7 / 64
我从 all_tab_columns 得到相同的结果(NULL)
.NET 代码:
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