简体   繁体   English

Oracle SQL-在视图的串联列上使用listagg

[英]Oracle SQL - using listagg on a concatenated column from a view

I created a view with a concatenated column. 我创建了一个带有串联列的视图。

I successfully used listagg on the individual columns, however when I attempted to use the concatenated column in the listagg, I received the error that it was an invalid identifier. 我在各个列上成功使用了listagg,但是当我尝试在listagg中使用串联的列时,我收到了一个错误消息,它是无效的标识符。

Is there a way to combine the requirement and message_desc columns in a listagg format? 有没有办法以listagg格式组合require和message_desc列?

my query is as follows: 我的查询如下:

select a.ID,
a.NAME,
a.YEAR,
count (a.linenum) as count_missing_docs,
listagg(a.requirement, ',') within group (order by a.requirement) as "reqs",
listagg(a.MESSAGE_DESC, '...')within group (order by a.MESSAGE_DESC)as "msgs",
listagg(a.combo,' ') within group (order by a.combo) as "all_info"
from
(SELECT
rownum "LINENUM",
FTR.ID,
FTR.NAME,
FTR.YEAR,
FTR.REQUIREMENT,
FTR.STATUS,
FTR.STATUS_IND,
FTR.MESSAGE_DESC,
FTR.REQUIREMENT||'-'||FTR.MESSAGE_DESC||'...' as "combo"
from TRACKING_REQUIREMENT FTR
where FTR.year = '1617'
and FTR.status = 'R'
and FTR.satisfied_ind = 'N'
order by 2 , 1 asc) A
group by
a.ID,
a.NAME,
a.YEAR
order by 1

The problem is actually just that you keep putting double quotes around your identifiers - this tells oracle that you want a case sensitive identifier, but then you're referring to it without double quotes, using a case-insensitive identifier (which Oracle seems to interpret internally as ALL UPPERCASE). 问题实际上是,您一直在标识符周围加上双引号-这告诉oracle您需要区分大小写的标识符,但是随后您要使用不区分大小写的标识符(不使用双引号)来引用它(Oracle似乎会解释内部为ALL大写)。

Just get rid of all the double quotes and your query should work fine. 只要删除所有双引号,您的查询就可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM