在 ORACLE 中创建视图
Create view in ORACLE
下面两种说法有什么不同吗
陈述一:
CREATE OR REPLACE VIEW ABC AS
SELECT "ORDER_NO","OBJKEY"
FROM TEST_TABLE;
陈述二:
CREATE OR REPLACE VIEW ABC AS
SELECT ORDER_NO,OBJKEY
FROM TEST_TABLE;
第二个语句没有双引号。我想知道有什么区别,Oracle 不会抱怨它会编译这两种代码。
它们在您的示例中完全相同。 From the documentation:
Every database object has a name. In a SQL statement, you represent the name of an object with a quoted identifier or a nonquoted identifier.
A quoted identifier begins and ends with double quotation marks ("). If you name a schema object using a quoted identifier, then you must use the double quotation marks whenever you refer to that object.
A nonquoted identifier is not surrounded by any punctuation.
You can use either quoted or nonquoted identifiers to name any database object. ...
和
Nonquoted identifiers are not case sensitive. Oracle interprets them as uppercase. Quoted identifiers are case sensitive.
因此,ORDER_NO
是不带引号且不区分大小写的,并且 Oracle 将名称视为大写 - 如此有效,当它在数据字典中查找匹配的列名称时(在 all_tab_columns
视图),它会查找确切的字符串值 'ORDER_NO'
。如果您没有引用 order_no
或 Order_No
或任何其他大小写组合,情况也会如此;因为它没有被引用,所以 Oracle 仍将其视为大写,并在内部查找 'ORDER_NO'
.
"ORDER_NO"
被引用,因此区分大小写,但无论如何它都是大写的,所以没有区别。 Oracle 仍在数据字典中查找名为 'ORDER_NO'
.
的列
如果实际对象标识符(例如列名)在数据字典中是大写的,那么无论您是将其作为非引号标识符提供还是作为大写的带引号标识符提供都没有关系。
您不能做的是使用引号和不同的大小写。 "ORDER_NO"
没问题; "order_no"
或 "Order_No"
或任何其他 引用 混合大小写将与数据字典中的内容不匹配。
虽然您可以使用非大写的带引号标识符(或者包括或以其他非法字符开头,如该文档中列出的规则所示)创建对象,但通常认为这是一个坏主意,因为您随后 总是 必须使用引号并且大小写完全相同。正如文档还指出的那样:
Oracle does not recommend using quoted identifiers for database object names. These quoted identifiers are accepted by SQL*Plus, but they may not be valid when using other tools that manage database objects.
下面两种说法有什么不同吗 陈述一:
CREATE OR REPLACE VIEW ABC AS
SELECT "ORDER_NO","OBJKEY"
FROM TEST_TABLE;
陈述二:
CREATE OR REPLACE VIEW ABC AS
SELECT ORDER_NO,OBJKEY
FROM TEST_TABLE;
第二个语句没有双引号。我想知道有什么区别,Oracle 不会抱怨它会编译这两种代码。
它们在您的示例中完全相同。 From the documentation:
Every database object has a name. In a SQL statement, you represent the name of an object with a quoted identifier or a nonquoted identifier.
A quoted identifier begins and ends with double quotation marks ("). If you name a schema object using a quoted identifier, then you must use the double quotation marks whenever you refer to that object.
A nonquoted identifier is not surrounded by any punctuation.
You can use either quoted or nonquoted identifiers to name any database object. ...
和
Nonquoted identifiers are not case sensitive. Oracle interprets them as uppercase. Quoted identifiers are case sensitive.
因此,ORDER_NO
是不带引号且不区分大小写的,并且 Oracle 将名称视为大写 - 如此有效,当它在数据字典中查找匹配的列名称时(在 all_tab_columns
视图),它会查找确切的字符串值 'ORDER_NO'
。如果您没有引用 order_no
或 Order_No
或任何其他大小写组合,情况也会如此;因为它没有被引用,所以 Oracle 仍将其视为大写,并在内部查找 'ORDER_NO'
.
"ORDER_NO"
被引用,因此区分大小写,但无论如何它都是大写的,所以没有区别。 Oracle 仍在数据字典中查找名为 'ORDER_NO'
.
如果实际对象标识符(例如列名)在数据字典中是大写的,那么无论您是将其作为非引号标识符提供还是作为大写的带引号标识符提供都没有关系。
您不能做的是使用引号和不同的大小写。 "ORDER_NO"
没问题; "order_no"
或 "Order_No"
或任何其他 引用 混合大小写将与数据字典中的内容不匹配。
虽然您可以使用非大写的带引号标识符(或者包括或以其他非法字符开头,如该文档中列出的规则所示)创建对象,但通常认为这是一个坏主意,因为您随后 总是 必须使用引号并且大小写完全相同。正如文档还指出的那样:
Oracle does not recommend using quoted identifiers for database object names. These quoted identifiers are accepted by SQL*Plus, but they may not be valid when using other tools that manage database objects.