Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
oracle sql对用例条件的澄清在where子句中,如果没有索引,则无法计算错误sdo_nn_Sql_Oracle - Fatal编程技术网

oracle sql对用例条件的澄清在where子句中,如果没有索引,则无法计算错误sdo_nn

oracle sql对用例条件的澄清在where子句中,如果没有索引,则无法计算错误sdo_nn,sql,oracle,Sql,Oracle,我正在使用oracle 11g和oracle spatial,如果我在where条件下使用以下距离,则此查询有效 mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance='|| c1.tier_radius||' unit=KM', 1) = 'TRUE' 但是,我希望根据条件计算距离。下面的查询给出了错误sdo_nn在没有索引的情况下无法计算,我希望根据类似这样的条件计算距离 select

我正在使用oracle 11g和oracle spatial,如果我在where条件下使用以下距离,则此查询有效

mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance='|| 
c1.tier_radius||' unit=KM', 1) = 'TRUE'
但是,我希望根据条件计算距离。下面的查询给出了错误sdo_nn在没有索引的情况下无法计算,我希望根据类似这样的条件计算距离

select
        /*+ first_rows LEADING(c) USE_NL(c1 b1) INDEX(b1 BRANCH_LOCATION_SPIX)*/
        b1.BRANCH_ID,
        mdsys.sdo_nn_distance(1) branchDistance
      from
        branch b1, city c1
      where
        mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance='|| (case  when b1.restaurant_id not in (3970,3971,3972) then c1.tier_radius
        else 15 end) ||' unit=KM', 1) = 'TRUE'   
        and b1.city_id = c1.city_id  
我们知道那部分

mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance='|| 
c1.tier_radius||' unit=KM', 1) = 'TRUE'
如果有效,那么我认为您可以使用这样一个包含
union all
的查询,如下所示:

select  /*+ first_rows LEADING(c) USE_NL(c1 b1) INDEX(b1 BRANCH_LOCATION_SPIX)*/
        b1.BRANCH_ID,
        mdsys.sdo_nn_distance(1) branchDistance
  from branch b1 
  join city c1 on c1.city_id = b1.city_id
 where mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance='||c1.tier_radius||' unit=KM', 1) = 'TRUE'
   and b1.restaurant_id not in (3970,3971,3972)
union all
select  /*+ first_rows LEADING(c) USE_NL(c1 b1) INDEX(b1 BRANCH_LOCATION_SPIX)*/
        b1.BRANCH_ID,
        mdsys.sdo_nn_distance(1) branchDistance
  from branch b1 
  join city c1 on c1.city_id = b1.city_id
 where mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance=15 unit=KM', 1) = 'TRUE'
   and b1.restaurant_id in (3970,3971,3972)
我们知道那部分

mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance='|| 
c1.tier_radius||' unit=KM', 1) = 'TRUE'
如果有效,那么我认为您可以使用这样一个包含
union all
的查询,如下所示:

select  /*+ first_rows LEADING(c) USE_NL(c1 b1) INDEX(b1 BRANCH_LOCATION_SPIX)*/
        b1.BRANCH_ID,
        mdsys.sdo_nn_distance(1) branchDistance
  from branch b1 
  join city c1 on c1.city_id = b1.city_id
 where mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance='||c1.tier_radius||' unit=KM', 1) = 'TRUE'
   and b1.restaurant_id not in (3970,3971,3972)
union all
select  /*+ first_rows LEADING(c) USE_NL(c1 b1) INDEX(b1 BRANCH_LOCATION_SPIX)*/
        b1.BRANCH_ID,
        mdsys.sdo_nn_distance(1) branchDistance
  from branch b1 
  join city c1 on c1.city_id = b1.city_id
 where mdsys.sdo_nn ( b1.location, l_location , 'SDO_BATCH_SIZE=100 distance=15 unit=KM', 1) = 'TRUE'
   and b1.restaurant_id in (3970,3971,3972)

是的,union all工作正常,但不会出现性能问题,因为union正在执行两个查询而不是一个查询?@Ayub我从未遇到与
union all
相关的任何性能问题(但是
union
可能会导致性能问题)。我觉得在提到错误SDO_NN的一个示例中,如果不使用索引yes union all works,就无法评估与这里提到的问题相关的内容,但是如果union正在执行两个查询而不是一个查询,是否会出现性能问题?@Ayub我从未遇到与
union all
(但是,
union
可能会导致性能问题)。我觉得这里提到的一个示例中提到的错误SDO_NN与此相关的一些内容在不使用索引的情况下无法进行评估查询是否可以使用此功能?
mdsys.SDO_NN(b1.location,l_location,'SDO_BATCH_SIZE=100 distance=15 unit=KM',1)='TRUE'
?查询是否与此相关?
mdsys.sdo\u nn(b1.location,l\u location,'sdo\u BATCH\u SIZE=100距离=15单位=KM',1)='TRUE'