下面是我的查询,我想访问UNQKEY值,我可以按顺序使用它,但我想在where条件中使用它。有没有想要使用UNQKEY作为条件的一部分?
SELECT distinct TOCID,'UNQKEY' || r UNQKEY ,TOCNAME,
decode( r, 1, UNQKEY1, 2, UNQKEY2, 3, UNQKEY3, 4, UNQKEY4 , 5, UNQKEY5) AS
UNQKEY_VALUE
FROM TOC, RULE RL,
(select rownum r
from all_objects
where rownum <=5)
WHERE TOCID=1210
ORDER BY UNQKEY
答案 0 :(得分:0)
如果要在where
子句中使用它,请使用子查询或CTE:
select *
from (select distinct TOCID, 'UNQKEY' || r as UNQKEY , TOCNAME,
decode( r, 1, UNQKEY1, 2, UNQKEY2, 3, UNQKEY3, 4, UNQKEY4 , 5, UNQKEY5) AS UNQKEY_VALUE
from TOC, RULE RL,
(select rownum r
from all_objects
where rownum <=5
)
) t
WHERE TOCID = 1210 and UNQKEY like '%%'
order by UNQKEY;