简体   繁体   English

Oracle内联视图列别名仅在连接表之前有效,而在连接到表时无效

[英]Oracle inline view column alias only working before joining tables and not when joining to tables

I have a query that looks somewhat like this: 我有一个查询,看起来像这样:

select
  ...,
  my_view.alias_name
from
  tbl1 join
  tbl2 on
    tbl1.key = tbl2.key join
  tbl3 on
    tbl3.key = tbl3.key join
  (
    select
      ...,
      (max(...) keep (...)) alias_name
    from
      ...
  ) my_view on
    tbl3.key = my_view.key
where
  ...;

It doesn't work because the alias_name isn't set (maintaining the name (max(...) keep (...)) which I don't know if its possible to reference in the select my_view.name_or_alias ) when I do it this way joining the inline view to the tables, but strangely enough it does work when I join the tables after the inline view instead. 它不起作用,因为未设置alias_name (保留名称(max(...) keep (...)) ,我不知道是否可以在select my_view.name_or_alias引用该select my_view.name_or_alias )这样可以将内联视图连接到表,但是奇怪的是,当我在内联视图之后连接表时,它确实可以工作。

select
  ...,
  my_view.alias_name
from
  (
    select
      ...,
      (max(...) keep (...)) alias_name
    from
      ...
  ) my_view join
  tbl3 on
    my_view.key = tbl3.key join
  tbl2 on
    tbl3.key = tbl2.key join
  tbl1 on
    tbl2.key = tbl1.key
where
  ...;

Is there any explanation or documentation that talks about this or is it undefined/random behavior? 是否有任何有关此的解释或文档,或者它是未定义/随机行为? Any way to make it work with the inline view joining the tables? 有什么方法可以使其与连接表的内联视图一起工作? I couldn't find any information about this. 我找不到有关此的任何信息。

The problem wasn't with Oracle nor the query after all but actually with Microsoft Query itself which was the program that was throwing the error. 问题不是不是Oracle也不是查询,而是实际上是Microsoft Query本身,后者是引发错误的程序。

It's old and I wish I didn't had to work with it... 它已经老了,我希望我不必再用它了...

Both of the following simplified queries work fine on Excel VBA but the second query doesn't on MS Query. 以下两个简化查询都可以在Excel VBA上正常运行,但第二个查询不适用于MS Query。

select
  *
from
  (
    select
      'X' dummy
    from
      dual
  ) my_view join
  dual on
    my_view.dummy = dual.dummy;

询问

select
  *
from
  dual join
  (
    select
      'X' dummy
    from
      dual
  ) my_view on
    dual.dummy = my_view.dummy;

MS查询错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM