问题描述
使用常规表时,可以使用以下Oracle SQL查询:
When using regular tables, its fine to use the following Oracle SQL query:
SELECT max(some_primary_key) FROM MyTable
但是,当使用数据库对象(即对象的表)时,会产生以下错误:
However, when using Database Objects (i.e. a table of an object), this yields to the following error:
ORA-00904: "SOME_PRIMARY_KEY": invalid identifier
在引用列名时,如下所示:
When quoting the column name, like this:
SELECT max("some_primary_key") FROM MyTable
这像预期的那样工作. 为什么在使用对象"而不是表"时必须转义列名?
This works like expected. Why is it necessary to escape column names when working with Objects, but not with Tables?
推荐答案
它与对象或表无关,而与这些对象/表的创建方式有关.
It doesn't have to do with objects or tables, it has to do with how these objects/tables have been created.
如果您这样做create table "blabla"
,那么您始终需要使用"blabla"来寻址该表,如果您执行create table blabla
,则可以通过BLABLA或blabla或bLabLa来寻址该表.使用" "
可以使名称区分大小写,这就是大多数开发人员不使用" "
的原因,因为通常您不希望区分大小写的名称.
If you do create table "blabla"
then you always need to address this table with "blabla", if you do create table blabla
then you can address this table via BLABLA or blabla or bLabLa. Using " "
makes the name case sensitive and that is the reason why most developers don't use " "
because usually you don't want case sensitive names .
这篇关于Oracle DB引号列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!