ORACLE遍历问题,条件中如果有LIKE会影响查询速度

解决方案 »

  1.   

    select count(*) from hn_guest where g_gname like '孙%'
    100万中,速度也很快啊,
      

  2.   

    一用到like时,oracle就会进行全表扫描
      

  3.   

    可不可以试试子查询?
    select count(*) from (select * from hn_guest where g_gname like '孙%') as a
    where a.g_indate>'200405010000' and a.g_indate<'200504010000'
    反正select count(*) from hn_guest where g_gname like '孙%'才三十多条,
    速度应该和select count(*) from hn_guest where g_gname like '孙%'速度差不多才是
      

  4.   

    Oracle好像不用写as,写了反而报错,试试这个:
    select count(*) from (select * from hn_guest where g_gname like '孙%') t1 where t1.g_indate>'200405010000' and t1.g_indate<'200504010000'
      

  5.   

    试试这个
    select count(*) from hn_guest where g_gname like '孙%' and g_indate>'200405010000' and g_indate<'200504010000'
      

  6.   

    建议看一些oracle优化的书
      

  7.   

    这样写
    select count(*) from 
    (
    select * 
    hn_guest where gg_indate<'200504010000' and _indate>'200405010000' 
    )
    where g_gname like '孙%'
      

  8.   

    如果是这样的条件:
    g_indate>'200405010000' and g_indate<'200504010000' and g_gname like '孙%'
    需要建立:
    (g_gname,g_indate)双列的索引
      

  9.   

    把execution plan贴上来,别人才能帮你,只是简单的介绍速度什么的,帮不了你的
    在sqlplus中
    set autotrace on
    set timing on
    然后执行你的语句以及h_wg(东方)写的语句
    select count(*) from (select * from hn_guest where g_gname like '孙%') t1 where t1.g_indate>'200405010000' and t1.g_indate<'200504010000'
    把显示的结果都贴上来
      

  10.   

    http://www.ddvip.net/database/oracle/index5/198.htm