【问题标题】:Invalid identifier on oracle inner joinoracle 内部连接上的标识符无效
【发布时间】:2012-05-08 13:56:16
【问题描述】:

我遇到错误 ORACLE: ORA-00904: Invalid Identifier on:

and l.cd_pergunta = e.cd_pergunta

无效的标识符是'e',cd_pergunta的前缀...

当我执行这个查询时:

select count(*)
  from TEACEITE e
 inner join TEREGETA re on re.cd_etapa = e.cd_etapa
                       and re.id_reg_neg = 1.00000000
 where e.obrigatorio = 1
   and not exists
 (select 1
          from GESESSAO s
         inner join GERESPOS r on r.sessao = s.sessao_resp
                              and r.resposta_log = 1
         inner join GEEPE l on l.cd_quest = s.cd_quest
                           and l.ord_perg = r.ord_pergunta
                           and l.cd_pergunta = e.cd_pergunta
         where s.cd_quest = e.cd_quest
           and s.item = e.cd_etapa
           and s.origem = 'GC'
           and s.os_nf_orc_cont = 1.00000000)

有什么想法吗?

【问题讨论】:

  • 更多关于相关深度限制的信息可以在下面找到(通常并且最终会存在某种方式来重写有问题的查询 - 相关子查询是否存在某种嵌套限制?): asktom.oracle.com/pls/apex/…

标签: database oracle oracle11g


【解决方案1】:

问题在于别名 e 在嵌套选择中不可用,因此是“无效标识符”。 您可以尝试重写查询,使条件s.cd_quest = e.cd_quest and s.item = e.cd_etapa 成为主选择的一部分,而不是嵌套选择。

编辑:我尝试了一些场景,问题是在嵌套查询的连接解析期间别名 e 不可用。看起来您不能在内部查询的连接条件中引用外部表别名。

我相信以下方法会起作用

  select count(*)
  from TEACEITE e
 inner join TEREGETA re on re.cd_etapa = e.cd_etapa
                       and re.id_reg_neg = 1.00000000
 where e.obrigatorio = 1
   and not exists
 (select 1
          from GESESSAO s
         inner join GERESPOS r on r.sessao = s.sessao_resp
                              and r.resposta_log = 1
         inner join GEEPE l on l.cd_quest = s.cd_quest
                           and l.ord_perg = r.ord_pergunta
         where l.cd_pergunta = e.cd_pergunta
           and s.cd_quest = e.cd_quest
           and s.item = e.cd_etapa
           and s.origem = 'GC'
           and s.os_nf_orc_cont = 1.00000000)

虽然此查询可能有效,但我不确定它是否完成了您想要的,请确保您的业务逻辑也得到处理。

【讨论】:

    【解决方案2】:

    正如 Raam 所说,您不能在子查询的连接中使用别名 e。
    也可以尝试不使用 sql1999 语法进行连接:

    select count(*)
      from TEACEITE e
     inner join TEREGETA re on re.cd_etapa = e.cd_etapa
                           and re.id_reg_neg = 1.00000000
     where e.obrigatorio = 1
       and not exists
     (select 1
        from GESESSAO s, GERESPOS r , GEEPE l 
       where r.sessao = s.sessao_resp
         and r.resposta_log = 1
         and l.cd_quest = s.cd_quest
         and l.ord_perg = r.ord_pergunta
         and l.cd_pergunta = e.cd_pergunta
         and s.cd_quest = e.cd_quest
         and s.item = e.cd_etapa
         and s.origem = 'GC'
         and s.os_nf_orc_cont = 1.00000000)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多