将Oracle亚型视为超级型

发布于 2025-01-27 06:24:22 字数 1816 浏览 4 评论 0 原文

我有一个使用Oracle的 mdsys .st_geometry类型的查询( link ):

select
    mdsys.st_point(1, 2, 26917)
from 
    dual

Output:
[MDSYS.ST_POINT]

查询输出ST_POINT sub sub 类型。

我想将ST_Point子类型转换为ST_GEOMETRY super 类型:

select
    treat(
        mdsys.st_point(1, 2, 26917)
    as st_geometry)
    .st_geometrytype() --optional; helps when running the query in DB<>FIDDLE or Oracle Live SQL, since those DBs don't output spatial types correctly.   
from 
    dual

Output:
ST_POINT

我认为我可以使用Treat()函数来进行转换。

treat()

您可以使用零食功能更改声明的类型 表达。

但是,正如您在上面的查询中看到的那样,即使我使用了Treat()函数,输出仍然是ST_POINT子类型,而不是ST_GEOMETRY SUPERTYPE。

就其价值而言,A


如何将Oracle子类型转换为其超模型?

相关: 2.3 sql对象类型中的继承

I have a query that uses Oracle's MDSYS.ST_GEOMETRY type (link):

select
    mdsys.st_point(1, 2, 26917)
from 
    dual

Output:
[MDSYS.ST_POINT]

The query outputs the ST_POINT subtype.

I want to convert the ST_POINT subtype to the ST_GEOMETRY supertype:

select
    treat(
        mdsys.st_point(1, 2, 26917)
    as st_geometry)
    .st_geometrytype() --optional; helps when running the query in DB<>FIDDLE or Oracle Live SQL, since those DBs don't output spatial types correctly.   
from 
    dual

Output:
ST_POINT

I would have thought that I could use the TREAT() function to make the conversion.

TREAT()

You can use the TREAT function to change the declared type of an
expression.

But as you can see in the query above, even though I used the TREAT() function, the output is still the ST_POINT subtype, not the ST_GEOMETRY supertype.

And for what it's worth, the same thing happens with a User-defined Type.


How can I convert an Oracle subtype to its supertype?

Related: 2.3 Inheritance in SQL Object Types

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

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

发布评论

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

评论(2

﹏雨一样淡蓝的深情 2025-02-03 06:24:22

ST_DEOMETRY使用SDO_DEOMETRY作为其存储。因此,您会假设由于不需要存储更改,因此TEART会愉快地返回ST_地理测定法。

选择mdsys.st_point(1,2,26917).geom.get_wkt()作为dual; dual;

转换可以直接进行,:

选择mdsys.st_geometry(mdsys.st_point(1,1,1,select>) 2,26917).geom)作为dual 的GEOM

The st_geometry uses sdo_geometry as its storage. So you would assume the TREAT would happily return the st_geometry as no storage change is needed.

select mdsys.st_point(1,2,26917).geom.get_wkt() as geom from dual;

Conversion can be done directly,:

select Mdsys.st_geometry(mdsys.st_point(1, 2, 26917).geom) as geom from dual

莳間冲淡了誓言ζ 2025-02-03 06:24:22

要构建 @Simon的答案,以下是Simon的查询的结果:

查询#1:

 select mdsys.st_point(1,2,26917).geom as geom from dual;
 --I removed .get_wkt().
 
 Result:
 [MDSYS.SDO_GEOMETRY]

查询#2:

 select Mdsys.st_geometry(mdsys.st_point(1, 2, 26917).geom) as geom from dual
 
 Result:
 [MDSYS.ST_GEOMETRY]

所以我认为这意味着两个查询都可以使用。他们将ST_Point子类型转换为ST_DEOMETRY SUPERTYPE。


我使用CTRL+F5在SQL开发人员中运行查询。如果我使用普通的F5,我会得到不同的结果,因为F5/sqlplus会自动将结果转换为几何形状的文本表示。因此,查询的结果将是点(1.0 2.0),这是一种误导。结果确实是 [mdsys.st_geometry]


相关: live sql中的不支持的数据类型:st_geometry(st_point(1,2,2,26917).geom)

To build on @Simon's answer, here are the results from Simon's queries:

Query #1:

 select mdsys.st_point(1,2,26917).geom as geom from dual;
 --I removed .get_wkt().
 
 Result:
 [MDSYS.SDO_GEOMETRY]

Query #2:

 select Mdsys.st_geometry(mdsys.st_point(1, 2, 26917).geom) as geom from dual
 
 Result:
 [MDSYS.ST_GEOMETRY]

So I think that means both queries worked. They converted the ST_POINT subtype to the ST_GEOMETRY supertype.


I used CTRL+F5 to run the queries in SQL Developer. If I'd used plain F5, I would have gotten different results, because F5/SQLPLUS automatically converts the result to a textual representation of the geometry. So the result for the queries would have been POINT (1.0 2.0), which is misleading. The result is really [MDSYS.ST_GEOMETRY].


Related: Unsupported datatype in Live SQL: st_geometry(st_point(1, 2, 26917).geom)

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