Noo*_*oob 2 oracle identifier case-when ora-00904
我在查询中遇到错误。此查询正常并返回数据(选择和行数用于分页):
select *
from (select a.*, rownum rnum
from (select id_edition, id_document, name, extension, creation_date, url,
(select inscription_date from edition_student_d0 where id_edition = 12345 and id_third = 12345) inscription_date
from upd_edition_doc_d0
where id_edition = 1071591
order by creation_date desc) a
where rownum <= 10 )
where rnum >= 1
Run Code Online (Sandbox Code Playgroud)
现在我尝试包含“case when”并仅在某些情况下获取 url,因此我进行了这些修改,包括 case 块:
select *
from (select a.*, rownum rnum
from (select id_edition, id_document, name, extension, creation_date,
(select inscription_date from edition_student_d0 where id_edition = 12345 and id_third = 12345) inscription_date,
case
when trunc(inscription_date + 90) <= trunc(sysdate) then null
else url
end url
from upd_edition_doc_d0
where id_edition = 1071591
order by creation_date desc) a
where rownum <= 10 )
where rnum >= 1
Run Code Online (Sandbox Code Playgroud)
Oracle启动这个错误:
ORA-00904: "INSCRIPTION_DATE": invalid identifier
Run Code Online (Sandbox Code Playgroud)
我想那是因为我要求 inscription_date 并在相同的查询级别使用它,但我不知道如何处理这个问题。
另外,我怎样才能做出我想做的事情?我的意思是,仅在特定条件下获取 url。
有人可以帮忙吗?
先感谢您。
您不能在同一级别的查询中引用别名。
您可以替换子查询...
select *
from (select a.*, rownum rnum
from (select id_edition, id_document, name, extension, creation_date,
(select inscription_date from edition_student_d0 where id_edition = 12345 and id_third = 12345) inscription_date,
case when trunc((select inscription_date from edition_student_d0 where id_edition = 12345 and id_third = 12345) + 90) <= trunc(sysdate) then null
else url
end as url
from upd_edition_doc_d0
where id_edition = 1071591
order by creation_date desc) a
where rownum <= 10 )
where rnum >= 1
Run Code Online (Sandbox Code Playgroud)
或者将案件上移一级。
select *
from (select a.*,
case when trunc(inscription_date + 90) <= trunc(sysdate) then null
else url
end as url,
rownum rnum
from (select id_edition, id_document, name, extension, creation_date,
(select inscription_date from edition_student_d0 where id_edition = 12345 and id_third = 12345) inscription_date
from upd_edition_doc_d0
where id_edition = 1071591
order by creation_date desc) a
where rownum <= 10 )
where rnum >= 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6697 次 |
| 最近记录: |