从Oracle表中获取几何坐标

时间:2013-09-23 08:39:27

标签: jquery sql oracle plsql erp

您好我需要从我的Oracle表中获取几何坐标。目前我使用

 (select column_value 
    from (
           select rownum r, 
                  b.* 
            from table(
                       select h.geometry.sdo_ordinates 
                        from hz_locations h 
                       where location_id =
                             (select location_id 
                                from csf_ct_tasks 
                               where task_id = p_task_id)
                       ) b
          )    -- location_id = 973,  task_id = 36420   

   where r =1) as latitude,


  (select column_value 
     from (
           select rownum r, 
                  b.* 
             from table(
                        select h.geometry.sdo_ordinates 
                          from hz_locations h 
                         where location_id =  
                               (select location_id 
                                  from csf_ct_tasks 
                                 where task_id = p_task_id)
                         ) b
            ) 

   where r =2) as longitude

此处p_task_id用于获取特定任务的纬度,经度。但我需要通过在外部查询中指定用户ID来获取单个用户的纬度,经度列表。是否可以重写我的查询。

我的实际选择语句是

SELECT all h.location_id,
       h.address1,
       h.address2,
       h.address3,
       h.address4,
       h.house_number,
       h.street_suffix,
       h.apartment_number,
       h.street,
       h.po_box_number,
       h.city,
       h.state,
       h.province,
       h.county,
       h.country,
       h.postal_code as customer_address
  from hz_locations h,
       csf_ct_tasks ct 
 where h.location_id = ct.location_id 
   and ct.owner_id = 10180

先谢谢。

![表中纬度和经度存储的样本响应] [2]

Actual table data

1 个答案:

答案 0 :(得分:1)

试试这个

WITH DATASET
    AS (SELECT
             CT.OWNER_ID OWNER_ID,
             ROWNUM R,
             H.GEOMETRY.SDO_ORDINATES VALUE
        FROM
             HZ_LOCATIONS H,
             CSF_CT_TASKS CT
        WHERE
             H.LOCATION_ID = CT.LOCATION_ID
             AND CT.OWNER_ID = 10180)
SELECT
      OWNER_ID,
      REGEXP_REPLACE ( VALUE,
                    '^([^,]*).*$',
                    '\1' )
          AS LAT,
      REGEXP_REPLACE ( VALUE,
                    '^[^,]*,|([^,]*).*$',
                    '\1' )
          AS LON
FROM
      DATASET
WHERE
      ROWNUM = 1;