我有一个使用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
发布评论
评论(2)
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
的GEOMThe 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
要构建 @Simon的答案,以下是Simon的查询的结果:
查询#1:
查询#2:
所以我认为这意味着两个查询都可以使用。他们将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:
Query #2:
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)