暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 具有1个以上参数的用户定义聚合函数

askTom 2017-08-17
397

问题描述

是否可以创建具有1个以上参数的用户定义的聚合函数?比方说,我想创建TOP_NTH (数字,整数) 函数,它采用一个数字 (为一列) 和整数,指示最高值的排名。这样的函数可以返回列中的top 2nd,top 3rd等值。
我知道有NTH_VALUE分析函数,所以我想知道是否可以创建类似的组函数。

专家解答

所以,让我们做一个快速测试:

create or replace type typ as object (
  x int
);
/

create or replace function nth_max (input number, nth number) 
return number parallel_enable aggregate using typ;
/
sho err

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      PL/SQL: Compilation unit analysis terminated
1/1      PLS-00652: aggregate functions should have exactly one argument


所以那将是一个编号。

进一步支持:

Restriction on AGGREGATE USING

You cannot specify the aggregate_clause for a nested function.

If you specify this clause, then you can specify only one input argument for the function.


http://docs.oracle.com/database/122/LNPLS/AGGREGATE-clause.htm#GUID-2ED21240-E45A-4982-B674-CF0E1BE0985B__AGGREGATE_CLAUSE-4E74B298
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论