Oracle - Can't use * sign with other column in select clause

前端 未结 3 1875
时光说笑
时光说笑 2021-01-23 04:56

Sorry if it\'s trivial, but selecting column with * sign isn\'t working always, and I don\'t find reference to this behavior.

I can select table A

3条回答
  •  遥遥无期
    2021-01-23 05:38

    The syntax diagram for select shows:

    The outermost path of that shows the plain, unprefixed * all-column wildcard on its own, and there is no loop back around for additional column expressions - all paths with a comma (to separate terms) are distinct from that plain * path.

    On the inner path that does allow a comma, and thus multiple expressions, you can only use .* prefixed by a table/view/alias, and can then follow (or precede) that with other expressions.

    (I really thought that was stated more clearly somewhere, but I can't find it anywhere in recent documentation...)

    Why i must use the alias for * sign ?

    select col,aa.* from A aa;
    

    That isn't quite accurate; you don't have to use an alias, you can use the table name directly if it isn't aliased, so this is also valid:

    select col,A.* from A;
    

    There is a school of thought that you shouldn't use a wildcard anyway, at least for anything except an ad hoc query - it's better to list all of the required column name explicitly, prefixed with the appropriate table name/alias particularly if there is a join, for clarity and to avoid unexpected issues with tables being modified. That's rather outside the scope of this question though *8-)

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题