取消引用对象时,为什么 Oracle 需要视图中列的别名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13106724/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:11:53  来源:igfitidea点击:

Why does Oracle require an alias for columns in a view when dereferencing an object?

sqloracle

提问by jsj

Why does Oracle require an alias for columns in a view when dereferencing an object?

取消引用对象时,为什么 Oracle 需要视图中列的别名?

For example:

例如:

CREATE VIEW view AS SELECT t.eno, t.workdept.dname, t.salary FROM table t
                                  *
ERROR at line 1:
ORA-00998: must name this expression with a column alias

(workdept is an object reference)

(workdept 是一个对象引用)

This can be fixed by changing t.workdept.dnameto t.workdept.dname AS alias.

这可以通过更改t.workdept.dname为 来解决t.workdept.dname AS alias

My question is, why is this enforced? Why not just use the attribute name workdept.dnameas would happen in an unaliased select e.g:

我的问题是,为什么要强制执行?为什么不像在无别名的选择中workdept.dname那样使用属性名称,例如:

SELECT t.eno, t.workdept.dname, t.salary FROM table t

SELECT t.eno, t.workdept.dname, t.salary FROM table t

(This works fine)

(这工作正常)

回答by deleted_user

First always use aliases.

首先总是使用别名。

Second, here is the oracle reason why, pertaining to views:

其次,这是关于视图的 oracle 原因:

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_8004.htm

http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_8004.htm

If you omit the aliases, the database derives them from the columns or column aliases in the query. For this reason, you must use aliases if the query contains expressions rather than only column names. Also, you must specify aliases if the view definition includes constraints.

如果省略别名,数据库将从查询中的列或列别名派生它们。因此,如果查询包含表达式而不仅仅是列名称,则必须使用别名。此外,如果视图定义包含约束,则必须指定别名。

Oracle treats an object reference as an expression not a table column.

Oracle 将对象引用视为表达式而不是表列。