oracle 不存在 lobc值,oracle11g – 使用wm_concat()获取ORA-22922(不存在的LOB值)或根本没有结果...

幸运的是,它适用于自11.2以来提供的listagg(…)函数(我们已经在运行),因此我们不必进一步调查:

listagg( abc,',' ) within group ( order by abc )

(正如人们应该知道的那样,wm_concat(…)是一些内部和官方不支持的功能.)

实现不同功能的rather nice solution(因为它不是那么臃肿)是通过自引用正则表达式功能实现的,这在许多情况下应该起作用:

regexp_replace(

listagg( abc,' ) within group ( order by abc ),'(^|,)(.+)(,\2)+','\1\2' )

(也许/希望我们将来会看到一些有效的listagg(不同的abc)功能,它会像wm_concat语法一样非常整洁和酷.例如,这是没有问题,因为很长一段时间与Postgres的string_agg(distinct abc)1)

-- 1: postgres sql example:

select string_agg( distinct x,' ) from unnest('{a,b,a}'::text[]) as x`

如果列表超过4000个字符,则不能再使用listagg(再次使用ORA-22922).

但幸运的是我们可以在这里使用xmlagg函数(如here所述).

如果你想在这里实现4000-chars截断结果的不同,你可以取消注释(1)标记的行.

-- in smallercase everything that could/should be special for your query

-- comment in (1) to realize a distinct on a 4000 chars truncated result

WITH cfg AS (

SELECT

',' AS list_delim,'([^,]+)(,\1)*(,|$)' AS list_dist_match,-- regexp match for distinct functionality

'\1\3' AS LIST_DIST_REPL -- regexp replace for distinct functionality

FROM DUAL

)

SELECT

--REGEXP_REPLACE( DBMS_LOB.SUBSTR( -- (1)

RTRIM( XMLAGG( XMLELEMENT( E,mycol,listdelim ).EXTRACT('//text()')

ORDER BY mycol ).GetClobVal(),LIST_DELIM )

--,4000 ),LIST_DIST_MATCH,LIST_DIST_REPL ) -- (1)

AS mylist

FROM mytab,CFG

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值