[英]Oracle sql - Invalid Identifier LISTAGG
我是新用的LISTAGG
功能。 當我運行以下腳本時,我收到一個無效的標識符錯誤:
ORA-00904:“TE”。“COUNTRY”:標識符無效
有什么想法嗎?
SELECT te.country, listagg(te.exception_date, ' ,') WITHIN GROUP (ORDER BY te.country) country
FROM
(select unique te.exception_date,
case when te.country is null then (select max(tt.country) from tt_transport tt where te.route = tt.route) else te.country end country
from tt_exception te
where trunc(te.exception_date) > '01-JAN-2015'
and te.plant = 'Z'
and not case when te.country is null then (select max(tt.country) from tt_transport tt where te.route = tt.route) else te.country end is null
order by te.country) te
group by te.country
UNION ALL
SELECT te.country, listagg(te.exception_date, ' ,') WITHIN GROUP (ORDER BY te.country) country
FROM
(select unique te.exception_date, 'GB' country
from tt_exception te
where trunc(te.exception_date) > '01-JAN-2015'
and te.plant = 'W'
and te.country is null
order by te.country)
group by te.country
在查詢的第二部分中,沒有為內聯視圖定義別名。 你應該命名它,然后引用它。
SELECT te.country, listagg(te.exception_date, ' ,') WITHIN GROUP (ORDER BY te.country) country
FROM
(select unique te.exception_date, 'GB' country
from tt_exception te
where trunc(te.exception_date) > '01-JAN-2015'
and te.plant = 'W'
and te.country is null
order by te.country) te --missing alias
group by te.country
或者您可以在沒有別名的情況下引用列名稱。
SELECT country, listagg(exception_date, ' ,') WITHIN GROUP (ORDER BY country) country
FROM
(select unique te.exception_date, 'GB' country
from tt_exception te
where trunc(te.exception_date) > '01-JAN-2015'
and te.plant = 'W'
and te.country is null
order by te.country)
group by country
SELECT te.country, listagg(te.exception_date, ' ,') WITHIN GROUP (ORDER BY te.country) country
FROM
(select unique te.exception_date,
case when te.country is null then (select max(tt.country) from tt_transport tt where te.route = tt.route) else te.country end country
from tt_exception te
where trunc(te.exception_date) > '01-JAN-2015'
and te.plant = 'Z'
and not case when te.country is null then (select max(tt.country) from tt_transport tt where te.route = tt.route) else te.country end is null
order by te.country) te
group by te.country
UNION ALL
SELECT te.country, listagg(te.exception_date, ' ,') WITHIN GROUP (ORDER BY te.country) country
FROM
(select unique te.exception_date, 'GB' country
from tt_exception te
where trunc(te.exception_date) > '01-JAN-2015'
and te.plant = 'W'
and te.country is null
order by te.country)--**you are missing the alias "te"**
group by te.country
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.