oracle 如何列出数据库中的表名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3762045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I list the table names in a database?
提问by Cnu
We have an Oracle 8i database on which I have only read access. We use ODBC and MS Access to read data from that database since we don't have Oracle Client software. This works fine. I am using ADO.NET with ASP.NET. Now I want to display a list of all the tables that I see in MS Access via ODBC. I have tried this with ODBC connection in C#. I am tried the following queries to get the list of tables, which did not work.
我们有一个 Oracle 8i 数据库,我只有读取权限。我们使用 ODBC 和 MS Access 从该数据库读取数据,因为我们没有 Oracle 客户端软件。这工作正常。我将 ADO.NET 与 ASP.NET 一起使用。现在我想通过 ODBC 显示我在 MS Access 中看到的所有表的列表。我已经用 C# 中的 ODBC 连接试过了。我尝试了以下查询来获取表列表,但没有用。
- select table_name from dba_tables;
- select table_name from all_tables;
- select tname from tab;
- 从 dba_tables 中选择 table_name;
- 从 all_tables 中选择 table_name;
- 从选项卡中选择 tname;
Please help.
请帮忙。
Thanks for the response. I tried them without luck. All I want to see is the same list of tables that are available in MS Access when I use ODBC to create Linked Tables.
感谢您的回复。我没有运气就试过了。当我使用 ODBC 创建链接表时,我只想看到 MS Access 中可用的相同表列表。
This is the function that I am using to achieve this, which does not really work the way I would have liked.
这是我用来实现这一目标的功能,它并没有真正按照我想要的方式工作。
public static ArrayList GetODBCTablesList()
{
try
{
OdbcConnection DbConnection = new OdbcConnection("DSN=mydsn;UID=user1;PWD=pwd1;");
DbConnection.Open();
OdbcCommand DbCommand = DbConnection.CreateCommand();
DbCommand.CommandText = "select table_name from all_tables";
OdbcDataReader DbReader = DbCommand.ExecuteReader();
if (DbReader != null)
{
ArrayList TableList = new ArrayList();
while (DbReader.Read())
{
TableList.Add(DbReader.GetString(0));
}
DbReader.Close();
DbCommand.Dispose();
DbConnection.Close();
TableList.Sort();
TableList.TrimToSize();
return TableList;
}
DbCommand.Dispose();
DbConnection.Close();
return null;
}
catch (Exception ex)
{
LogHandler.WriteLogMessage(ex.GetBaseException().ToString(), true);
return null;
}
}
This gives me a list of tables which does not contain all the tables that I see when I link tables in MS Access using ODBC.
这给了我一个表列表,其中不包含我使用 ODBC 在 MS Access 中链接表时看到的所有表。
回答by Jeremy Goodell
This works:
这有效:
select table_name from tabs;
回答by Sathyajith Bhat
You can try
select table_name from user_tables
你可以试试
select table_name from user_tables
or
或者
select object_name from USER_objects where object_type='TABLE'
select object_name from USER_objects where object_type='TABLE'
回答by bouvierr
Since you're using ADO.NET, I would suggest to use OdbcConnection.GetSchema. This method returns a DataTable
containing information about the schema of your database.
由于您使用的是 ADO.NET,我建议您使用OdbcConnection.GetSchema。此方法返回DataTable
有关数据库架构的包含信息。
From this answer, this might work for you:
从这个答案,这可能对你有用:
OdbcConnection.GetSchema("Tables")
OdbcConnection.GetSchema("表")