DB2 函数返回错误 SQL CODE 4743?
DB2 functions returning error SQL CODE 4743?
一段时间以来,我一直在努力解决这个问题。我有一个名为 Students
的 table,例如:
ID |Classes |Priority
----------------------------
3 A51 1
3 B51 2
3 K5B 2
3 M5A 2
4 XN5 1
5 XN5 1
5 A51 2
9 BX1 1
9 BX2 2
9 AK3 2
我现在正在使用 DBVisualizer 来执行我的语句,但我正在尝试使用名为 LISTAGG()
的东西作为 DB2 函数:
SELECT
ID,
LISTAGG(classes, ',') within GROUP (ORDER BY Priority) AS GROUPED_CLASSES
FROM
Students
GROUP BY
ID;
但是,每次我尝试 运行 这个时,我都会收到这个错误:
1) [Code: -4743, SQL State: 56038] ATTEMPT TO USE A FUNCTION WHEN THE APPLICATION COMPATIBILITY SETTING IS SET FOR A PREVIOUS LEVEL. SQLCODE=-4743, SQLSTATE=56038, DRIVER=4.22.29
2) [Code: -514, SQL State: 26501] THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=4.22.29
而且我不知道如何解决它或为什么会这样。我试着研究这个,有人建议这样做:
SET CURRENT APPLICATION COMPATIBILITY = 'V11R1'
但是这也没有运气,即使它 运行.
同样的错误
我还尝试用 SELECT GETVARIABLE('SYSIBM.VERSION') FROM SYSIBM.SYSDUMMY1
和这个 returns DSN12015 查看我的 DB2 版本(不知道这是什么意思)。
我正在拼命寻找答案或一些帮助,非常感谢。目标是让结果看起来像:
ID |Grouped_Classes |
-----------------------------
3 A51, B51, K5B, M5A
4 XN5
5 XN5, A51
9 BX1, BX2, AK3
试试这个:
/*
WITH STUDENTS (ID, Classes, Priority) AS
(
SELECT 3, 'A51', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 3, 'M5A', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 4, 'XN5', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 5, 'XN5', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 3, 'B51', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 3, 'K5B', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 5, 'A51', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 9, 'BX1', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 9, 'BX2', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 9, 'AK3', 2 FROM SYSIBM.SYSDUMMY1
)
*/
SELECT
ID
, SUBSTR (XMLSERIALIZE (XMLAGG (XMLTEXT (',' || CLASSES) ORDER BY PRIORITY) AS CLOB (100)), 2)
AS GROUPED_CLASSES
FROM STUDENTS
GROUP BY ID
ID
GROUPED_CLASSES
3
A51,K5B,M5A,B51
4
XN5
5
XN5,A51
9
BX1,BX2,AK3
一段时间以来,我一直在努力解决这个问题。我有一个名为 Students
的 table,例如:
ID |Classes |Priority
----------------------------
3 A51 1
3 B51 2
3 K5B 2
3 M5A 2
4 XN5 1
5 XN5 1
5 A51 2
9 BX1 1
9 BX2 2
9 AK3 2
我现在正在使用 DBVisualizer 来执行我的语句,但我正在尝试使用名为 LISTAGG()
的东西作为 DB2 函数:
SELECT
ID,
LISTAGG(classes, ',') within GROUP (ORDER BY Priority) AS GROUPED_CLASSES
FROM
Students
GROUP BY
ID;
但是,每次我尝试 运行 这个时,我都会收到这个错误:
1) [Code: -4743, SQL State: 56038] ATTEMPT TO USE A FUNCTION WHEN THE APPLICATION COMPATIBILITY SETTING IS SET FOR A PREVIOUS LEVEL. SQLCODE=-4743, SQLSTATE=56038, DRIVER=4.22.29
2) [Code: -514, SQL State: 26501] THE CURSOR SQL_CURLH200C1 IS NOT IN A PREPARED STATE. SQLCODE=-514, SQLSTATE=26501, DRIVER=4.22.29
而且我不知道如何解决它或为什么会这样。我试着研究这个,有人建议这样做:
SET CURRENT APPLICATION COMPATIBILITY = 'V11R1'
但是这也没有运气,即使它 运行.
我还尝试用 SELECT GETVARIABLE('SYSIBM.VERSION') FROM SYSIBM.SYSDUMMY1
和这个 returns DSN12015 查看我的 DB2 版本(不知道这是什么意思)。
我正在拼命寻找答案或一些帮助,非常感谢。目标是让结果看起来像:
ID |Grouped_Classes |
-----------------------------
3 A51, B51, K5B, M5A
4 XN5
5 XN5, A51
9 BX1, BX2, AK3
试试这个:
/*
WITH STUDENTS (ID, Classes, Priority) AS
(
SELECT 3, 'A51', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 3, 'M5A', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 4, 'XN5', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 5, 'XN5', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 3, 'B51', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 3, 'K5B', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 5, 'A51', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 9, 'BX1', 1 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 9, 'BX2', 2 FROM SYSIBM.SYSDUMMY1
UNION ALL SELECT 9, 'AK3', 2 FROM SYSIBM.SYSDUMMY1
)
*/
SELECT
ID
, SUBSTR (XMLSERIALIZE (XMLAGG (XMLTEXT (',' || CLASSES) ORDER BY PRIORITY) AS CLOB (100)), 2)
AS GROUPED_CLASSES
FROM STUDENTS
GROUP BY ID
ID | GROUPED_CLASSES |
---|---|
3 | A51,K5B,M5A,B51 |
4 | XN5 |
5 | XN5,A51 |
9 | BX1,BX2,AK3 |