如何获取在oracle 11g中为特定用户创建的所有表的元数据

时间:2015-04-21 07:34:43

标签: java oracle oracle11g

我在oracle 11g中有一个名为testUser的用户。现在我在用户testUser下有4个表。我想仅为用户testUser下存在的所有表获取元数据。 我正在使用接口java.sql.DatabaseMetaData中提供的getTables方法。方法的签名如下:

getTables(java.lang.String catalog,
java.lang.String schemaPattern,
java.lang.String tableNamePattern,
java.lang.String[] types);

任何人都可以帮助我理解应该在getTables方法的第一个和第二个参数中传递的值。 我认为在第三个参数tableNamePattern中,我必须传递"%"在第四个参数中,我将仅使用一个元素传递字符串数组" TABLE"因为我必须取桌子。

我不确定第一个和第二个参数值。如果我在第一个和第二个参数中传递null,它会尝试获取oracle中存在的所有用户的所有表。但我想在单个用户下创建表格。

提前致谢。

2 个答案:

答案 0 :(得分:0)

根据oracle文档:  的的getTables

ResultSet getTables(String catalog,
                    String schemaPattern,
                    String tableNamePattern,
                    String[] types)
                    throws SQLException

Retrieves a description of the tables available in the given catalog. Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_CAT, TABLE_SCHEM and TABLE_NAME.

Each table description has the following columns:

    TABLE_CAT String => table catalog (may be null)
    TABLE_SCHEM String => table schema (may be null)
    TABLE_NAME String => table name
    TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
    REMARKS String => explanatory comment on the table
    TYPE_CAT String => the types catalog (may be null)
    TYPE_SCHEM String => the types schema (may be null)
    TYPE_NAME String => type name (may be null)
    SELF_REFERENCING_COL_NAME String => name of the designated "identifier" column of a typed table (may be null)
    REF_GENERATION String => specifies how values in SELF_REFERENCING_COL_NAME are created. Values are "SYSTEM", "USER", "DERIVED". (may be null) 

Note: Some databases may not return information for all tables.

Parameters:
    catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
    schemaPattern - a schema name pattern; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search
    tableNamePattern - a table name pattern; must match the table name as it is stored in the database
    types - a list of table types, which must be from the list of table types returned from getTableTypes(),to include; null returns all types 
Returns:
    ResultSet - each row is a table description 

缩短

  1. 第一个参数catalog只是服务器实例
  2. 第二个参数schema只是数据库中的命名空间,与用户帐户相同

答案 1 :(得分:0)

您可以为第一个参数传递null,并为第二个参数传递用户名(TESTUSER - 大写很重要)。目录对Oracle数据库无关紧要,schemaPattern(name)和用户名在Oracle数据库中是相同的。