In OceanBase Database in Oracle mode, you can use the GET_WKB(), GET_WKT(), and GET_GEOJSON() member functions of the SDO_GEOMETRY type to convert a spatial object of the SDO_GEOMETRY type to a Well-Known-Binary (WKB) data format, a Well-Known-Text (WKT) data format, or a JSON data format.
GET_WKB()
The GET_WKB() function converts a spatial object to a binary string in the Well-Known-Binary (WKB) data format. The WKB format is a standard binary format for representing spatial geometric objects.
Here is an example:
obclient [SYS]> SELECT SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1,1), SDO_ORDINATE_ARRAY(10,500)).GET_WKB() AS test_get_wkb FROM dual;
The return value is as follows:
+--------------------------------------------+
| TEST_GET_WKB |
+--------------------------------------------+
| 00000000014024000000000000407F400000000000 |
+--------------------------------------------+
1 row in set
GET_WKT()
The GET_WKT() function converts a spatial object to a string in the Well-Known-Text (WKT) data format. The WKT format is a standard text format for representing spatial geometric objects.
Here is an example:
obclient [SYS]> SELECT SDO_GEOMETRY(2001, NULL, SDO_POINT_TYPE(10, 50, NULL), NULL, NULL).GET_WKT() AS test_get_wkt FROM dual;
The return value is as follows:
+---------------+
| TEST_GET_WKT |
+---------------+
| POINT (10 50) |
+---------------+
1 row in set
GET_GEOJSON()
The GET_GEOJSON() function converts a spatial object to a string in the JSON data format.
Here is an example:
obclient [SYS]> SELECT SDO_GEOMETRY(2001, NULL, NULL, SDO_ELEM_INFO_ARRAY(1,1,1), SDO_ORDINATE_ARRAY(10,500)).GET_GEOJSON() AS test_get_geojson FROM dual;
The return value is as follows:
+-----------------------------------------------+
| TEST_GET_GEOJSON |
+-----------------------------------------------+
| { "type": "Point", "coordinates": [10, 500] } |
+-----------------------------------------------+
1 row in set
