未找到具有兼容参数的 "FUNCTION" 类型的名为 "JSON_ARRAYAGG" 的授权例程

No authorized routine named "JSON_ARRAYAGG" of type "FUNCTION" having compatible arguments was found

未找到具有兼容参数的类型为“FUNCTION”的名为“JSON_ARRAYAGG”的授权例程 在 DB2 中使用 JSON_ARRAYAGG 函数时出错:

    QUERY:
        SELECT JSON_OBJECT('ACCT_ID' VALUE acct_id, 
        'use_case list' VALUE 
        JSON_ARRAYAGG(
        JSON_OBJECT('use_case' VALUE use_case,
        'stage' VALUE stage))) 
        FROM NULLID.ProductRecommendations 
        GROUP BY acct_id;
            
    Error:
            FAILED  [SELECT - 0 rows, 0.009 secs]  1) [Code: -440, SQL State: 42884]  No authorized routine named "JSON_ARRAYAGG" of type "FUNCTION" having compatible arguments was found.. SQLCODE=-440, SQLSTATE=42884, DRIVER=4.26.14
                2) [Code: -727, SQL State: 56098]  An error occurred during implicit system action type "2". Information returned for the error includes SQLCODE "-440", SQLSTATE "42884" and message tokens "JSON_ARRAYAGG|FUNCTION".. SQLCODE=-727, SQLSTATE=56098, DRIVER=4.26.14  

我已经在示例表上尝试过此查询,仍然出现相同的错误:

    Person Table:
    create table NULLID.person
    (
      id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
      name        varchar(50),
      PRIMARY KEY (id)
    );
        
    Contacts Table:
        create table NULLID.contacts
        (
          id INT,
          person_id int,
          key   varchar(50),
          value varchar(100),
          foreign key (person_id) references person (id)
        );
        
    Insert Queries:
    insert into NULLID.person values (1, 'A');
    insert into NULLID.person values (2, 'B');
    insert into NULLID.contacts values (1, 1, 'EMAIL', 'a@b.com');
    insert into NULLID.contacts values (2, 1, 'PHONE', '123');
    insert into NULLID.contacts values (3, 2, 'EMAIL', 'b@b.com');
    insert into NULLID.contacts values (4, 2, 'PHONE', '456');
        
    Query:  
SELECT
    person_id,
    JSON_ARRAYAGG(key)
FROM
    contacts
GROUP BY person_id
        
        
    Error:
16:17:44  FAILED  [SELECT - 0 rows, 0.009 secs]  1) [Code: -440, SQL State: 42884]  No authorized routine named "JSON_ARRAYAGG" of type "FUNCTION" having compatible arguments was found.. SQLCODE=-440, SQLSTATE=42884, DRIVER=4.26.14
2) [Code: -727, SQL State: 56098]  An error occurred during implicit system action type "2". Information returned for the error includes SQLCODE "-440", SQLSTATE "42884" and message tokens "JSON_ARRAYAGG|FUNCTION".. SQLCODE=-727, SQLSTATE=56098, DRIVER=4.26.14  

请理解您必须使用正确的文档来匹配 Db2 产品平台。对于 Db2,存在三个主要平台(Linux/Unix/Windows(LUW)、Z/OS 和 i-series(as/400)。此外,Db2-on-cloud 的功能略有不同(和不同的知识中心)与常规 on-premises Db2-LUW.

您引用的 Db2-for-i (as/400) 页面是 不同的 产品(具有不同的 SQL 语法) Db2-on-cloud。所以Db2-on-cloud没有那个功能json_arrayagg(虽然Db2 for i系列当前版本有那个功能)

请使用正确的 Db2 知识中心-on-cloud,位于此处

https://www.ibm.com/support/knowledgecenter/SSFMBX/com.ibm.swg.im.dashdb.kc.doc/welcome.html

云上的 Db2 语法是使用函数 JSON_ARRAY 和相关函数。您可以使用此查询查看哪些 JSON 函数可用: select routinename from syscat.routines where routinename like 'JSON%' (假设您有正确的访问权限)。