# ST_Equals

## 定义

ST_Equals 比较两个 ST_Geometries，如果这两个几何完全相同，则返回 1 (Oracle) 或 t (PostgreSQL)；否则返回 0 (Oracle) 或 f (PostgreSQL)。

## 语法

`sde.st_equals (g1 sde.st_geometry, g2 sde.st_geometry)`

## 示例

Oracle

``````CREATE TABLE bldgs (bldg_id integer unique,
footprint sde.st_geometry);

INSERT INTO BLDGS (bldg_id, footprint) VALUES (
1,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

INSERT INTO BLDGS (bldg_id, footprint) VALUES (
2,
sde.st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0)
);

INSERT INTO BLDGS (bldg_id, footprint) VALUES (
3,
sde.st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 0)
);

INSERT INTO BLDGS (bldg_id, footprint) VALUES (
4,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);
``````

PostgreSQL

``````CREATE TABLE bldgs (bldg_id integer unique,
footprint st_geometry);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
1,
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
2,
st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 0)
);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
3,
st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 0)
);

INSERT INTO bldgs (bldg_id, footprint) VALUES (
4,
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);
``````

Oracle

``````SELECT UNIQUE (b1.bldg_id), b2.bldg_id
FROM BLDGS b1, BLDGS b2
WHERE sde.st_equals (b1.footprint, b2.footprint) = 1
AND b1.bldg_id <> b2.bldg_id;

BLDG_ID   BLDG_ID

4           1
1           4
``````

PostgreSQL

``````SELECT DISTINCT (b1.bldg_id), b2.bldg_id
FROM bldgs b1, bldgs b2
WHERE st_equals (b1.footprint, b2.footprint) = 't'
AND b1.bldg_id <> b2.bldg_id;

bldg_id   bldg_id

1           4
4           1
``````
9/15/2013