[英]Oracle sql - Invalid Identifier LISTAGG
I'm new using the LISTAGG
function. 我是新用的
LISTAGG
功能。 When I run the following script I get an invalid identifier error: 当我运行以下脚本时,我收到一个无效的标识符错误:
ORA-00904: "TE"."COUNTRY": invalid identifier
ORA-00904:“TE”。“COUNTRY”:标识符无效
Any ideas why? 有什么想法吗?
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
In the second part of the query, there is no alias defined for the inline view. 在查询的第二部分中,没有为内联视图定义别名。 You should name it and then refer to it.
你应该命名它,然后引用它。
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
Or you can just refer to the column name without the alias. 或者您可以在没有别名的情况下引用列名称。
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.