This article will explore the Sdo_Geometery data type in Oracle 21c, including its syntax, advantages, and example usage.

### Introduction to Oracle Sdo_Geometery Datatype

Oracle uses the data type SDO GEOMETRY to store and work with spatial data. It is a feature of the Oracle Spatial and Graph option, which enables database users to work with geospatial data.

Points, lines, polygons, and circles are examples of geometric objects that can be represented using the SDO GEOMETRY datatype. It is an extremely effective tool for geographical analysis and has many potential uses.

Also, check: Oracle interval Datatype

### How does SDO_GEOMETRY work?

SDO GEOMETRY holds spatial information as a collection of points and lines. The geometric shape of the thing being stored is then shown using these points and lines. The type of item, its coordinates, and its spatial reference system are just a few of the features that the SDO GEOMETRY datatype’s list of attributes that describe the object being stored.

Several spatial functions that are included in Oracle can be utilized in conjunction with the SDO GEOMETRY datatype. Users can use these functions to conduct operations on spatial data, such as computing areas, measuring distances, and performing spatial joins across several datasets.

## Applications of SDO_GEOMETRY

The SDO_GEOMETRY datatype has a wide range of applications in various industries, including:

- Applications involving geographic analysis frequently employ the SDO GEOMETRY datatype. It can be used to carry out spatial queries, such as locating all points that are a specific distance from a specific location or all polygons that cross a specific line.
- Transportation: To store data regarding roads, railroads, and other transportation infrastructure, applications using the SDO GEOMETRY datatype are used in the transportation sector. It is possible to plan routes, estimate trip times, and improve transportation systems using this data.
- Applications for environmental monitoring employ the SDO GEOMETRY datatype to track changes in the environment over time. It can be used to keep track of the locations of woods, water bodies, and other natural features as well as to track how land usage has changed over time.
- Urban planning: The SDO_GEOMETRY datatype is used in urban planning applications to store information about buildings, roads, and other urban infrastructure. This information can be used to plan new developments, optimize traffic flow, and monitor changes in land use patterns over time.

Read: Oracle rowid Datatype

### Advantages of SDO_GEOMETRY

There are several advantages of using the SDO_GEOMETRY datatype in Oracle. Here are some of the key benefits:

- Efficient spatial data storage and retrieval are made possible by the SDO GEOMETRY datatype. The small binary format used to store geometric objects reduces the quantity of data required and expedites query processing.
- Easy integration with other Oracle features: The SDO GEOMETRY datatype is fully compatible with both the SQL and PL/SQL programming languages. As a result, spatial data integration into applications and spatial analysis within databases are made simple.
- Many spatial operations: The Oracle-provided range of spatial operations is compatible with the SDO GEOMETRY datatype. These features enable users to do complex spatial studies and queries, such as proximity analysis, area calculations and buffer operations.
- Improved data quality: The SDO_GEOMETRY datatype enables users to store spatial data in a consistent and standardized format, which can improve data quality and reduce errors. This is particularly important in applications where spatial data accuracy is critical, such as in transportation and urban planning.

### Oracle SDO_GEOMETRY datatype Syntax

The syntax for declaring a column with the SDO_GEOMETRY datatype in Oracle 21c is as follows:

```
SDO_GEOMETRY(
type, -- geometry type code
srid, -- spatial reference identifier
point, -- point object or NULL
elem_info, -- element information array or NULL
ordinates -- array of ordinates or NULL
);
```

Where:

**‘type’**: is the numeric code that specifies the type of geometry, such as 2001 for a point, 2003 for a polygon, or 2005 for a multi-polygon.**‘srid’**: is the spatial reference identifier that specifies the coordinate system in which the geometry is represented. This is an optional parameter and can be set to NULL if the coordinate system is not specified.**‘point’**: is an SDO_POINT_TYPE object that represents a point in two-dimensional space. This is an optional parameter and can be set to NULL if the geometry does not include a point object.**‘elem_info’**: is an array of integers that specifies the structure of the geometry, such as the type and number of elements in a multi-polygon. This is an optional parameter and can be set to NULL if the geometry does not include element information.**‘ordinates’**: an array of ordinates that represent the coordinates of the geometry. This is an optional parameter and can be set to NULL if the geometry does not include ordinates.

Note that the point, elem_info, and ordinates parameters are mutually exclusive we can only specify one of them for a given geometry.’

### Example of SDO_GEOMETRY Datatype in Oracle 21c

First, we’ll create a table with a column of type **SDO_GEOMETRY** to hold our polygon data:

```
CREATE TABLE polygons (
id NUMBER,
shape SDO_GEOMETRY
);
```

Next, we’ll insert a row into the table with an **SDO_GEOMETRY** object representing a polygon:

```
INSERT INTO polygons (id, shape)
VALUES (
1,
SDO_GEOMETRY(
2003, -- 2D polygon
NULL, -- coordinate system
NULL,
SDO_ELEM_INFO_ARRAY(1,1003,1),
SDO_ORDINATE_ARRAY(0,0, 0,10, 10,10, 10,0, 0,0)
)
);
select * from polygons;
```

In this example, the SDO_GEOMETRY object represents a square polygon with vertices at (0,0), (0,10), (10,10), and (10,0).

Also, check: Oracle Blob Datatype

### Disadvantages of SDO_GEOMETRY

- Complexity: Working with SDO GEOMETRY requires specific knowledge because it is a complex data type. For users unfamiliar with the technology, creating spatial queries and applications using SDO GEOMETRY can be difficult.
- Performance: SDO GEOMETRY queries may be slower than conventional relational queries, depending on the volume and complexity of the data. This is because handling spatial data and doing geometric computations adds extra work.
- Storage Needs: Storing spatial data in the SDO GEOMETRY format can necessitate a large increase in storage capacity compared to previous formats. This is because supporting spatial queries necessitates additional metadata and indexing.
- Limited compatibility: While SDO_GEOMETRY can support a wide range of spatial data types, it may not be compatible with all types of data used in other GIS applications. This can limit interoperability with other systems and applications.

Conclusion:

In this article, we have covered the Sdo_Geometery data type in Oracle 21c, including its syntax, advantages, and example usage.

Also, take a look at some more Oracle tutorials.

I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.

Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.