有两个选择语句:
select max(min(str)) from (select 0 id, 'a' str from dual) group by id having min(str) = 'a';
select strconcat(min(str)) from (select 0 id, 'a' str from dual) group by id having min(str) = 'a';
唯一的区别是外部聚合函数:
max()
与strconcat()
。您可以将
strconcat()
替换为您拥有的任何UDAF。前一条语句按预期工作:返回字符串
'a'
。后者声明:
-(在Oracle 10g上)给出错误的结果(用null代替字符串
'a'
)-(在Oracle 11g上)引发
ORA-00979: not a GROUP BY expression
我不明白此错误消息。
您能解释一下这种行为吗?
它是Oracle错误吗?
最佳答案
10克:
似乎我可以使用的WM_CONCAT
(是的,没有记录,但在这种情况下没有关系)或您使用的STRCONCAT
(或也许其他功能)需要提高一个级别。看这个例子:
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
SQL> select max(min(str)) result
2 from (select 0 id, 'a' str from dual)
3 group by id having min(str) = 'a';
R
-
a
SQL> -- returns NULL, just as you've said
SQL> select wm_concat(min(str)) result
2 from (select 0 id, 'a' str from dual)
3 group by id having min(str) = 'a';
RESULT
---------------------------------------------------------------------
SQL> -- but, if we put it a level "up", the result is OK
SQL> select wm_concat(minstr) result
2 from (select min(str) minstr
3 from (select 0 id, 'a' str from dual)
4 group by id having min(str) = 'a'
5 );
RESULT
---------------------------------------------------------------------
a
SQL>
11克:
好的,两个查询(我在这里使用
listagg
):SQL> select max(min(str)) result
2 from (select 0 id, 'a' str from dual)
3 group by id having min(str) = 'a';
R
-
a
SQL>
SQL> select listagg(min(str), ',') within group (order by null) result
2 from (select 0 id, 'a' str from dual)
3 group by id having min(str) = 'a';
RESULT
-----------------------------------------------------------------------
a
SQL>
那么,这是一个错误吗?我不知道
关于sql - SELECT UDAF(AGGR())中的怪异行为,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52038384/