甲骨文 | "ORA-00942: table or view does not exist" 在 with 子句中

Oracle | "ORA-00942: table or view does not exist" in with-clause

我需要编写如下查询 - 给出的查询仅用于概念。

我得到 ORA-00942: table or view does not exist for view table inner_nested_table used in with clause.

首先,这样使用合法吗?如果没有,有没有我可以使用的解决方法。

select
    inner_nested_table.column1,
    inner_nested_table.column2,
    inner_nested_table.column3,
    (
        with test as (
            select
                column4, column5
            from
                inner_nested_table
        )
        select column4 from test
    ) columnX
from
    (
    select
        column1,
        column2,
        column3,
        column4,
        column5
    from
        actual_table
    ) inner_nested_table;

test sub-query 嵌套太深,SQL 引擎无法找到 inner_nested_table。 Oracle 支持查找嵌套一级而不是两层的别名。

相反,您可以使用:

WITH inner_nested_table AS (
  select column1,
         column2,
         column3,
         column4,
         column5
  from   actual_table
),
test AS (
  select column4
  from   inner_nested_table
)
select column1,
       column2,
       column3,
       (select column4 from test) AS columnX
from   inner_nested_table;

db<>fiddle here