Oracle:SELECT与应用转换,除非字段为空

时间:2012-06-13 08:46:36

标签: sql oracle spatial

我有以下声明,我试图针对Oracle表运行,以便将一组结果返回导出:

SELECT 
   a.CLUSTER_ID, 
   SDO_CS.transform(a.CELL_GEOM, 4326).GET_WKT()  CELL_GEOM, 
   SDO_CS.transform(a.CELL_CENTROID, 4326).GET_WKT()  CELL_CENTROID, 
   SDO_CS.transform(a.CLUSTER_CENTROID, 4326).GET_WKT()  CLUSTER_CENTROID, 
   a.NUM_POINTS, 
   a.FEATURE_PK, 
   SDO_CS.transform(a.CLUSTER_EXTENT, 4326).GET_WKT()  CLUSTER_EXTENT
FROM HIGHWAYS.CLUSTER_128000M a

当我针对我的数据集运行此操作时,出现以下错误:

ORA-06531: Reference to uninitialized collection
ORA-06512: at "MDSYS.SDO_CS", line 2553
ORA-06512: at "MDSYS.SDO_CS", line 2678

这是由于某些字段在数据库中可能为空而导致(我相信)。如何修改代码以将此考虑在内并且如果字段为空则不尝试应用转换?一旦代码运行,我将导出到SQL Server,由于SQL Server在转换时无用,我在Oracle中应用它们之前将数据复制到Oracle中的WGS84(27700)中,我需要它在4326时稍后从SQL Server检索它。

1 个答案:

答案 0 :(得分:1)

尝试:

SELECT a.CLUSTER_ID,
       CASE
           WHEN a.CELL_GEOM IS NOT NULL THEN SDO_CS.transform(a.CELL_GEOM, 4326).GET_WKT()
           ELSE a.CELL_GEOM.GET_WKT()
       END CELL_GEOM,
       CASE
           WHEN a.CELL_CENTROID IS NOT NULL THEN SDO_CS.transform(a.CELL_CENTROID, 4326).GET_WKT()
           ELSE a.CELL_CENTROID.GET_WKT()
       END CELL_CENTROID,
       CASE
           WHEN a.CLUSTER_CENTROID IS NOT NULL THEN SDO_CS.transform(a.CLUSTER_CENTROID, 4326).GET_WKT()
           ELSE a.CLUSTER_CENTROID.GET_WKT()
       END CLUSTER_CENTROID,
       a.NUM_POINTS,
       a.FEATURE_PK,
       CASE
           WHEN a.CLUSTER_EXTENT IS NOT NULL THEN SDO_CS.transform(a.CLUSTER_EXTENT, 4326).GET_WKT()
           ELSE a.CLUSTER_EXTENT.GET_WKT()
       END CLUSTER_EXTENT
FROM HIGHWAYS.CLUSTER_128000M a