[英]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.