其实这只是对null的一个处理,但这样的话索引就起不到作用了,所以性能会差

解决方案 »

  1.   

    还是不明白这些话
    where nvl(Ect_Job,' ') like :shp_job_no
    and nvl(ECT_INVOICE_NO,' ') like :shp_inv_no如果 shp_job_no参数为空会出现什么样的语句  ?
    这个使用OacQruery组件的, 在参数中看到有个默认值为"%" 类型为STRING
    where '' like % and ectinvoice_no like 'hhjj29993'
      

  2.   

    Select *
    From Secstp00 
    where nvl(Ect_Job,' ') like 'HY16981'
    and nvl(ECT_INVOICE_NO,' ') like '%'i/o成本:31 60个字节 全表扫描
    而我换成
    Select *
    From Secstp00 
    where ect_job like 'HY16981'
    and ECT_INVOICE_NO like '%'
    i/o成本:2 540个字节 索引范围扫描
    无法理解的是 为什么要用 nvl(Ect_Job,' ') 呢? 
    一般来讲 like左边都是字段名称啊,右边才是要查找的值! 写这个语句的人走了!!
      

  3.   

    无法理解的是 为什么要用 nvl(Ect_Job,' ') 呢? 
    一般来讲 like左边都是字段名称啊,右边才是要查找的值! 没有什么不可理解左                    右
    NULL                  NULL
    not null              not null
    null                  not null
    not null              null
    性能方面建立函数索引就可以吧?
      

  4.   

    无法理解的是 为什么要用 nvl(Ect_Job,' ') 呢?
    左                    右
    '空格' like '%'  呀?
      

  5.   

    我的理解是: nvl(Ect_Job,'')    如果Ect_Job是null值,nvl返回0  下边like '%' 的比较肯定不成立,如果 Ect_Job非null值,nvl返回当前字段Ect_Job的值,接下来就是 like 运算的比较了
    是把字段like比配查询,和字段null值替换,两种功能写在一起了,不过效率相当不乐观!
    关键是理解nvl函数的返回值,我在网上查到了一下说明,供楼主参考:
    The NVL function lets you substitutes a non-value when a null value is encountered.The syntax for the NVL function is:NVL (string1, replace_with )string1 is the string to test for a null value. replace_with is the value returned if string1 is null. Example:select NVL (commission, 0)
    from sales;This SQL statement would return 0 if the commission field contained a null value. Otherwise, it would return the commission field.