oracle 11g 游标中的 Listagg

Listagg in cursor in oracle 11g

我正在尝试创建一个在其 select 语句中使用 LISTAGG 的游标 fetch_table_info。

create or replace PROCEDURE testcheck is 
cursor fetch_table_info is       
select LISTAGG(B.COLUMN_NAME,'||'',''||')       
WITHIN GROUP (ORDER BY B.COLUMN_POSITION)       
from USER_IND_COLUMNS B       
where  B.TABLE_NAME=B.INDEX_NAME and b.TABLE_NAME='TEST_TAB'; 
begin 
dbms_output.put_line(SQLERRM); 
end; 
/

select 语句单独执行良好,但编译程序时出现以下错误

发现'LISTAGG',只有CUME_DIST、DENSE_RANK、PERCENT_RANK、RANK、PERCENTILE_CONT和PERCENTILE_DISC适用于 WITHIN GROUP

提前致谢!

看来您使用的是旧版本的 Toad,它无法识别 Oracle 11gR2 中引入的 listagg 函数。

From the Dell support site:

Description
The 11gR2 new analytic function LISTAGG is not recognised by syntax checker.

...

The code above runs ok but if we try to format it, the following error message appears:

ERROR line 4, col 10, ending_line 4, ending_col 16, Found listagg, Only CUME_DIST, DENSE_RANK, PERCENT_RANK, RANK, PERCENTILE_CONT and PERCENTILE_DISC are valid with WITHIN GROUP

Cause
The parser in version 10.1 does not support this 11gR2 function

Resolution
Toad for Oracle 11.0 and above support this. You can download the latest version of Toad using http://bit.ly/noHL20

... 这有趣地指向一个旧的 Quest URL,它只是重定向到 Dell 支持登录页面。看起来你可以 get the current version here.