我遇到错误ORACLE:ORA-00904:无效的标识符:
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)
有什么想法吗?
答案 0 :(得分:6)
问题是别名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)
虽然这个查询可能有效,但我不确定它是否能完成您的需求,请确保您的业务逻辑也得到了解决。
答案 1 :(得分:0)
正如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)