如何获取在 oracle 11g 中为特定用户创建的所有表的元数据
How to fetch metadata for all tables created for particular user in oracle 11g
我在 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 中存在的所有用户的所有表。但是我想fecth在单用户下创建的表。
提前致谢。
根据 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
简而言之
- 第一个参数
catalog
只是服务器实例
- 第二个参数
schema
只是数据库中的命名空间,与用户帐户相同
您可以为第一个参数传递 null,为第二个参数传递用户名(TESTUSER - 大写很重要)。 Catalog 与 Oracle 数据库无关,schemaPattern (name) 和 username 在 Oracle 数据库中是相同的。
我在 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 中存在的所有用户的所有表。但是我想fecth在单用户下创建的表。
提前致谢。
根据 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
简而言之
- 第一个参数
catalog
只是服务器实例 - 第二个参数
schema
只是数据库中的命名空间,与用户帐户相同
您可以为第一个参数传递 null,为第二个参数传递用户名(TESTUSER - 大写很重要)。 Catalog 与 Oracle 数据库无关,schemaPattern (name) 和 username 在 Oracle 数据库中是相同的。