Oracle string_agg(distinct columnname) 在 pl/sql 中不起作用,仅在 sqldeveloper 中起作用
我正在尝试获取 string_agg 函数,详细信息此处来使用独特的关键字。示例用法:
select string_agg(distinct a.name), a.id from tbl_a a group by a.id
问题是这在 sqldeveloper 中有效,但是当在匿名 pl/sql 块中的应用程序 Express 中运行它时,它拒绝接受 unique 关键字,并且我收到一条错误,指出不允许使用 unique 。为什么它会这样做?有一个简单的解决方法吗?我正在使用 10.2 和 applicationexpress 3.2
编辑:澄清一下,我有兴趣解决这个问题,但如果有另一个我可以使用的 string_agg/group_concat 函数,我愿意接受任何想法。
编辑:我最终希望能够做类似的事情
select string_agg(distinct a.name),string_agg(distinct a.city), a.id from tbl_a a group by a.id
,并且对两个 string_agg 列进行重复数据删除...在子查询中使用不同的值时这是一个问题,因为它没有获得两列的不同值...
I am trying to get the string_agg function, detailed here to work with the distinct keyword. Sample usage:
select string_agg(distinct a.name), a.id from tbl_a a group by a.id
The problem is that this works in sqldeveloper, but when running it in application express in an anonymous pl/sql block, it refuses to accept the distinct keyword and I get an error saying that the distinct is not allowed. Why would it be doing this? Is there a simple workaround? I am using 10.2 and application express 3.2
Edit: to clarify, I am interested in solving this problem, but if there is another string_agg/group_concat function that I can use I am open to any ideas.
Edit: I eventually want to be able to do something like
select string_agg(distinct a.name),string_agg(distinct a.city), a.id from tbl_a a group by a.id
and have both string_agg columns be deduped... this is a problem when using a distinct in a subquery as it does not get the distinct values for both columns...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
水果列表
苹果、樱桃、柠檬
FRUIT_LIST
Apple,Cherries,Lemon
根据此 AskTom 线程。
将不同的操作移动到子查询中应该可以:
This behaviour seems to be a bug according to the last post in this AskTom thread.
Moving the distinct operation into a sub query should work: