简体   繁体   English

如何在数据库中列出表名?

[英]How do I list the table names in a database?

We have an Oracle 8i database on which I have only read access. 我们有一个Oracle 8i数据库,我只有读取权限。 We use ODBC and MS Access to read data from that database since we don't have Oracle Client software. 我们使用ODBC和MS Access从该数据库读取数据,因为我们没有Oracle客户端软件。 This works fine. 这很好用。 I am using ADO.NET with ASP.NET. 我在ASP.NET中使用ADO.NET。 Now I want to display a list of all the tables that I see in MS Access via ODBC. 现在我想显示我通过ODBC在MS Access中看到的所有表的列表。 I have tried this with ODBC connection in C#. 我在C#中尝试使用ODBC连接。 I am tried the following queries to get the list of tables, which did not work. 我尝试了以下查询来获取表的列表,这些表不起作用。

  1. select table_name from dba_tables; 从dba_tables中选择table_name;
  2. select table_name from all_tables; 从all_tables中选择table_name;
  3. select tname from tab; 从标签中选择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中的表时看到的所有表。

这有效:

select table_name from tabs;

Since you're using ADO.NET, I would suggest to use OdbcConnection.GetSchema . 由于您使用的是ADO.NET,我建议使用OdbcConnection.GetSchema This method returns a DataTable containing information about the schema of your database. 此方法返回一个DataTable其中包含有关数据库架构的信息。

From this answer , this might work for you: 这个答案 ,这可能对你有用:

OdbcConnection.GetSchema("Tables") OdbcConnection.GetSchema( “表”)

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'

Try: 尝试:

SELECT owner, table_name
  FROM dba_tables

Taken from Get list of all tables in Oracle? 摘自Oracle中所有表的获取列表?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM