简体   繁体   English

当使用小写的表名时,DatabaseMetaData.getColumns()返回空的ResultSet,但是在上层使用右侧的ResultSet

[英]DatabaseMetaData.getColumns() returns empty ResultSet when use table name in lower case,but the right ResultSet in upper

I use oracle 11g,and create a table like this: 我使用oracle 11g,并创建一个这样的表:

create table test1(
id int,
name varchar(10),
inserttime date
)

Then I use the jdbc method 然后我使用jdbc方法

DatabaseMetaData.getColumns(null, null, "test1", null)

and get empty ResultSet. 并得到空的ResultSet。 but when I use 但是当我用的时候

DatabaseMetaData.getColumns(null, null, "TEST1", null)

I can get the right ResultSet. 我可以得到正确的ResultSet。

Why? 为什么?

This is because internally, OracleDatabaseMetaData.getColumns() executes a query against the all_tab_columns data dictionary view, where it matches the table name pattern against all_tab_columns.table_name . 这是因为在内部, OracleDatabaseMetaData.getColumns()all_tab_columns数据字典视图执行查询,该视图与all_tab_columns.table_name的表名模式匹配。

By convention, Oracle stores identifiers (such as the table name here) in data dictionaries in uppercase format. 按照惯例,Oracle以大写格式在数据字典中存储标识符(例如此处的表名)。 You can verify this by executing the following query in the db: 您可以通过在db中执行以下查询来验证这一点:

SELECT * FROM all_tab_columns t where t.table_name = 'TEST1';

The case-sensitivity of the table identifier here is indeed counter-intuitive, especially because table identifiers are case-insensitive in Oracle SQL. 这里表标识符的区分大小写确实是违反直觉的,特别是因为表标识符在Oracle SQL中不区分大小写。

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

相关问题 DatabaseMetaData.getColumns返回同义词的空ResultSet - DatabaseMetaData.getColumns returning an empty ResultSet for synonyms 具有异常的表的DatabaseMetaData.getColumns,而resultSet.next()即ORA-01427:单行子查询返回多行 - DatabaseMetaData.getColumns of a table having exception while resultSet.next() i.e ORA-01427: single-row subquery returns more than one row Java DatabaseMetaData.getSchemas() 返回空 ResultSet,预期非空 ResultSet - Java DatabaseMetaData.getSchemas() returns empty ResultSet, expected non-empty ResultSet DatabaseMetaData.getColumns 对于 int 值有奇怪的列大小 - DatabaseMetaData.getColumns has strange column size for int value Java DatabaseMetaData.getColumns() 方法不适用于所有用户 - Java DatabaseMetaData.getColumns() method doesn't work for all users DatabaseMetaData.getColumns()给SQL Server 2008错误 - DatabaseMetaData.getColumns() giving error with SQL Server 2008 SQL语句在空表上返回结果集 - SQL statement returns a resultset on an empty table 为什么ResultSet meteData getColumnName得到所有大写的列名 - Why ResultSet meteData getColumnName got all Upper case column name executeQuery()返回空的ResultSet - executeQuery() returns empty ResultSet 与MySQL连接时结果集返回空 - The resultset returns empty when connecting with MySQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM