在 oracle 中将 group by 与数组一起使用

Zor*_*eza 5 oracle

有没有办法在使用 GROUP BY 命令时获取数组列?我试图从 oracle 数据库中获取几何作为坐标数组,但是在尝试使用命令 GROUP BY 时出现错误

SELECT A.C_ID, 
       A.ID,
       COUNT(T.Text),
       LISTAGG(T.TEXT, '/// ') WITHIN GROUP (ORDER BY NULL) text, 
       P.GEOMETRY.sdo_ordinates p_geom
FROM G_P_THEME A 
LEFT JOIN G_POLYGON P on P.C_ID=A.C_ID and P.ID=A.ID 
LEFT JOIN  G_P_TEXT T on P.C_ID=T.C_ID and P.ID=T.ID 
WHERE (A.THEME_ID=440 OR A.THEME_ID=47) 
Group by A.C_ID, A.ID
Having (COUNT(T.Text) > 1);
Run Code Online (Sandbox Code Playgroud)

它返回一个错误

ORA-00979: not a GROUP BY expression
00979. 00000 -  "not a GROUP BY expression"
*Cause:    
*Action:
Run Code Online (Sandbox Code Playgroud)

我知道这是因为如果我在 GROUP BY 中添加 P.GEOMETRY.sdo_ordinates 在 GROUP BY 命令中没有对 P.GEOMETRY 的引用,结果将是

ORA-00932: inconsistent datatypes: expected - got MDSYS.SDO_ORDINATE_ARRAY
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:
Error at Line: 6 Column: 32
Run Code Online (Sandbox Code Playgroud)

如果 GROUP BY 中只有 P_GEOMETRY

ORA-22901: cannot compare VARRAY or LOB attributes of an object type
22901. 00000 -  "cannot compare VARRAY or LOB attributes of an object type"
*Cause:    Comparison of VARRAY or LOB attributes of an object type
           was attempted in the absence of a MAP or ORDER method.
*Action:   Define a MAP or ORDER method for the object type.
Error at Line: 6 Column: 32
Run Code Online (Sandbox Code Playgroud)

可能需要在 SELECT 中使用一些东西来避免在 GROUP BY 中使用它,但无法弄清楚是什么

Zor*_*eza 0

可以在链接中找到最佳解决方案。从数据库读取数据比Balazs Papp建议的解决方案要快得多。

只是在 Balazs 答案中提到“仅获取前 1 行”需要在旧版本中使用 ROWNUM=1 进行更改。