//创建表
CREATE TABLE TestSpatial (
ID VARCHAR2(20) NOT NULL,
NAME VARCHAR2(100),
ADDRESS VARCHAR2(200),
TELEPHONE VARCHAR2(50),
LOCATION SDO_GEOMETRY
);
//插入数据
INSERT INTO TestSpatial
VALUES(
'dbeb7ea11eaf2b53a9b7',
'小肥羊(天河店)',
'广州市天河区天寿路25号',
'020-38217746',
MDSYS.SDO_GEOMETRY(
2001,
8307,
MDSYS.SDO_POINT_TYPE(113.3293658, 23.14338586, 0),
NULL,
NULL
)
);
INSERT INTO TestSpatial
VALUES(
'ef8393ef6273a72b2f70',
'山东老家',
'广州市越秀区合群一马路43号',
'020-87778983',
MDSYS.SDO_GEOMETRY(
2001,
8307,
MDSYS.SDO_POINT_TYPE(113.2932474, 23.11883515, 0),
NULL,
NULL
)
);
//给数据库系统user_sdo_geom_metadata表中插入所建表的空间字段数据
insert into user_sdo_geom_metadata(table_name,COLUMN_NAME, DIMINFO, SRID)
values(
'TestSpatial',
'location',
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.005), //经度范围(-180,180)0.005误差范围
MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.005) //纬度范围(-90,90,)
),
8307 //默认为NULL笛卡尔坐标系,8307代表wgs84坐标系
)
//元数据创建错误时删除方法
delete from user_sdo_geom_metadata where COLUMN_NAME = 'location'
//以表的空间字段创建索引
CREATE INDEX SPATIAL_IDX ON TestSpatial(location) INDEXTYPE IS MDSYS.SPATIAL_INDEX;