title: Oracle spatial data operator - SDO_nn - Not getting any results for sdo_num_res = 1
body: <p>I am using SDO_NN operator to find the nearest hydrant next to a building.</p>
  
  <p>Building:</p>
  
  <pre><code>CREATE TABLE  "BUILDINGS" 
  (   
  "NAME" VARCHAR2(40), 
  "SHAPE" "SDO_GEOMETRY") 
  </code></pre>
  
  <p>Hydrant:</p>
  
  <pre><code>CREATE TABLE  "HYDRANTS" 
     (    "NAME" VARCHAR2(10), 
  "POINT" "SDO_POINT_TYPE"
    );
  </code></pre>
  
  <p>I have setup spatial indexes properly for buildings.shape and I run the query to get the nearest hydrant to the building 'Motel'    </p>
  
  <pre><code>select b1.name as name, h.point.x as x, h.point.y as y  from buildings b1, hydrants h where  b1.name ='Motel'  and
                      SDO_nn( b1.shape, MDSYS.SDO_GEOMETRY(2003,NULL, NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),
                              SDO_ORDINATE_ARRAY( h.point.x,h.point.y)), 'sdo_num_res=1')= 'TRUE';
  </code></pre>
  
  <p><b>Here's the problem:</b></p>
  
  <p>When I set the parameter<i> sdo_num_res=1</i>, I get zero tuples.
  And when I make  sdo_num_res=2, I get one tuple.</p>
  
  <p>What is the reason for the weird behavior ? </p>
  
  <p>Note: I am getting zero rows only when building.name= 'Motel', for all other tuples I am getting 1 row when sdo_num_res = 1</p>
  
  <p>Edit:
  Insert queries</p>
  
  <pre><code>Insert into buildings (NAME,SHAPE) values ('Motel',MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),MDSYS.SDO_ORDINATE_ARRAY(564,425,585,436,573,458,552,447)));
  
  Insert into hydrants  (name,POINT) values ('p57',MDSYS.SDO_POINT_TYPE(589,448,0));
  </code></pre>