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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:32:37  来源:igfitidea点击:

How do I list the table names in a database?

c#oracleado.net

提问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 连接试过了。我尝试了以下查询来获取表列表,但没有用。

  1. select table_name from dba_tables;
  2. select table_name from all_tables;
  3. select tname from tab;
  1. 从 dba_tables 中选择 table_name;
  2. 从 all_tables 中选择 table_name;
  3. 从选项卡中选择 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 DataTablecontaining 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("表")

回答by Gage

Try:

尝试:

SELECT owner, table_name
  FROM dba_tables

Taken from Get list of all tables in Oracle?

取自获取 Oracle 中所有表的列表?