Domanda

Hi I need to get geometric coordinates from my Oracle table. Currently I use

 (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

Here p_task_id is used to get a particular latitude, longitude of a task. But I need to get list of latitude, longitude of a single user by specifying user id in outer query. Is it possible to rewrite my query.

My Actual select statement is

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

Thanks in Advance.

![Sample response of the latitude and longitude store in the table][2]

Actual table data

È stato utile?

Soluzione

Try this

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top