将顶点排入嵌套表类型(由ID汇总)

发布于 2025-02-06 20:12:51 字数 2166 浏览 1 评论 0 原文

测试数据:

with cte as (
select 1 as id, 100 as x, 101 as y from dual union all
select 1 as id, 200 as x, 201 as y from dual union all
select 2 as id, 300 as x, 301 as y from dual union all
select 2 as id, 400 as x, 401 as y from dual union all
select 2 as id, 500 as x, 501 as y from dual union all
select 3 as id, 600 as x, 601 as y from dual union all
select 3 as id, 700 as x, 701 as y from dual union all
select 3 as id, 800 as x, 801 as y from dual union all
select 3 as id, 900 as x, 901 as y from dual)

select id, x, y from cte

        ID          X          Y
---------- ---------- ----------
         1        100        101
         1        200        201

         2        300        301
         2        400        401
         2        500        501

         3        600        601
         3        700        701
         3        800        801
         3        900        901

在SQL查询中:

我想将顶点折叠到由ID列汇总的嵌套表中。

数据类型将是Oracle Spatial的Mdsys.vertex_set_type:

mdsys.vertex_set_type

此功能返回mdsys.vertex_set_type的对象, 由mdsys.vertex_type的对象表组成。甲骨文空间 并图将类型定义为vertex_set_type为:

 创建类型Vertex_set_type作为vertex_type的表;
 

oracle空间和图将对象类型Vertex_type定义为:

 创建类型type vertex_type作为对象    
(x数字,
 y数字,
 z号,
 W号,
 V5号,
 V6号,
 V7号,
 V8号,
 v9号,
 V10号,
 V11号,
 ID号); - 顶点ID属性在这里。
 

认为结果看起来像这样:(三组顶点)

VERTICES
---------------------
MDSYS.VERTEX_SET_TYPE([MDSYS.VERTEX_TYPE], [MDSYS.VERTEX_TYPE])
MDSYS.VERTEX_SET_TYPE([MDSYS.VERTEX_TYPE], [MDSYS.VERTEX_TYPE])
MDSYS.VERTEX_SET_TYPE([MDSYS.VERTEX_TYPE], [MDSYS.VERTEX_TYPE])

--I mocked up that format using this dummy query:  
--select  sdo_util.getvertices(sdo_geometry('linestring(100 101, 200 201)')) from dual

oracle空间和图将

我 顶点排入vertex_set_type表类型 - 由ID列汇总?

Test data:

with cte as (
select 1 as id, 100 as x, 101 as y from dual union all
select 1 as id, 200 as x, 201 as y from dual union all
select 2 as id, 300 as x, 301 as y from dual union all
select 2 as id, 400 as x, 401 as y from dual union all
select 2 as id, 500 as x, 501 as y from dual union all
select 3 as id, 600 as x, 601 as y from dual union all
select 3 as id, 700 as x, 701 as y from dual union all
select 3 as id, 800 as x, 801 as y from dual union all
select 3 as id, 900 as x, 901 as y from dual)

select id, x, y from cte

        ID          X          Y
---------- ---------- ----------
         1        100        101
         1        200        201

         2        300        301
         2        400        401
         2        500        501

         3        600        601
         3        700        701
         3        800        801
         3        900        901

In an SQL query:

I want to collapse the vertices into nested tables, aggregated by the ID column.

The datatype would be Oracle Spatial's MDSYS.VERTEX_SET_TYPE:

MDSYS.VERTEX_SET_TYPE

This function returns an object of MDSYS.VERTEX_SET_TYPE, which
consists of a table of objects of MDSYS.VERTEX_TYPE. Oracle Spatial
and Graph defines the type VERTEX_SET_TYPE as:

CREATE TYPE vertex_set_type as TABLE OF vertex_type;

Oracle Spatial and Graph defines the object type VERTEX_TYPE as:

CREATE TYPE vertex_type AS OBJECT    
(x   NUMBER,
 y   NUMBER,
 z   NUMBER,
 w   NUMBER,
 v5  NUMBER,
 v6  NUMBER,
 v7  NUMBER,
 v8  NUMBER,
 v9  NUMBER,
 v10 NUMBER,
 v11 NUMBER,
 id  NUMBER);  --The vertex ID attribute is down here.

I think the result would look something like this: (three sets of vertices)

VERTICES
---------------------
MDSYS.VERTEX_SET_TYPE([MDSYS.VERTEX_TYPE], [MDSYS.VERTEX_TYPE])
MDSYS.VERTEX_SET_TYPE([MDSYS.VERTEX_TYPE], [MDSYS.VERTEX_TYPE])
MDSYS.VERTEX_SET_TYPE([MDSYS.VERTEX_TYPE], [MDSYS.VERTEX_TYPE])

--I mocked up that format using this dummy query:  
--select  sdo_util.getvertices(sdo_geometry('linestring(100 101, 200 201)')) from dual

Question:

Is there a way to collapse the vertex rows into the VERTEX_SET_TYPE table type — aggregated by the ID column?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯淡〆 2025-02-13 20:12:51

使用收集聚合函数,然后 cast 它到 mdsys.vertex_set_type

WITH cte (id, x, y) as (
  SELECT 1, 100, 101 FROM DUAL UNION ALL
  SELECT 1, 200, 201 FROM DUAL UNION ALL
  SELECT 2, 300, 301 FROM DUAL UNION ALL
  SELECT 2, 400, 401 FROM DUAL UNION ALL
  SELECT 2, 500, 501 FROM DUAL UNION ALL
  SELECT 3, 600, 601 FROM DUAL UNION ALL
  SELECT 3, 700, 701 FROM DUAL UNION ALL
  SELECT 3, 800, 801 FROM DUAL UNION ALL
  SELECT 3, 900, 901 FROM DUAL
)
SELECT id,
       CAST(
         COLLECT(
           MDSYS.VERTEX_TYPE(x, y, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, id)
           ORDER BY x, y
         )
         AS MDSYS.VERTEX_SET_TYPE
       )
FROM   cte
GROUP BY id

db<> fiddle 在这里

Use the COLLECT aggregation function and then CAST it to MDSYS.VERTEX_SET_TYPE:

WITH cte (id, x, y) as (
  SELECT 1, 100, 101 FROM DUAL UNION ALL
  SELECT 1, 200, 201 FROM DUAL UNION ALL
  SELECT 2, 300, 301 FROM DUAL UNION ALL
  SELECT 2, 400, 401 FROM DUAL UNION ALL
  SELECT 2, 500, 501 FROM DUAL UNION ALL
  SELECT 3, 600, 601 FROM DUAL UNION ALL
  SELECT 3, 700, 701 FROM DUAL UNION ALL
  SELECT 3, 800, 801 FROM DUAL UNION ALL
  SELECT 3, 900, 901 FROM DUAL
)
SELECT id,
       CAST(
         COLLECT(
           MDSYS.VERTEX_TYPE(x, y, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, id)
           ORDER BY x, y
         )
         AS MDSYS.VERTEX_SET_TYPE
       )
FROM   cte
GROUP BY id

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文