原文: http://www.cnblogs.com/crazyjava/archive/2012/10/31/2748202.html

instr(string1,string2[,start_position[,nth_appearence]])

string1:要在此字符串中查找。

string2:要在string1中查找的字符串。

start_position:从string1开始查找的位置。可选,默认为1,正数时,从左到右检索,负数时,从右到左检索。

nth_appearence:查找第几次出现string2。可选,默认为1,不能为负。

注:如果没有查找到,返回0。

例如:

select instr('abcd','a') from dual;  --返回1
select instr('abcd','c') from dual;  --返回3
select instr('abcd','e') from dual;    --返回0

该函数可以用于模糊查询以及判断包含关系:

例如:

① select code, name, dept, occupation  from staff  where instr(code, '001') > 0;

  等同于

  select code, name, dept, occupation  from staff  where code like '%001%' ;

② select ccn,mas_loc from mas_loc where instr('FH,FHH,FHM',ccn)>0;

  等同于

  select ccn,mas_loc from mas_loc where ccn in ('FH','FHH','FHM');

另一篇文章:

表中将近有100万数据,很多时候,我们要进行字符串匹配,在SQL语句中,我们通常使用like来达到我们搜索的目标。但经过实际测试发现,like的效率与instr函数差别相当大。

SQL> set timing on
SQL> select count(*) from t where instr(title,’oracle’)>0;

COUNT(*)
———-
5478

Elapsed: 00:00:11.04
SQL> select count(*) from t where title like ‘%oracle%’;

COUNT(*)
———-
5478

Elapsed: 00:00:31.47

注:

instr(title,'oracle’)>0 相当于like

instr(title,'oracle’)=0 相当于not like

Oracle instr 及 like的更多相关文章

  1. Oracle instr用法

    1:实现indexOf功能,.从第1个字符开始,搜索第1次出现子串的位置 ,) as i from dual; select instr('oracle','or') as i from dual; ...

  2. oracle instr函数(oracle 用instr 来代替 like)

    oracle instr函数 对于instr函数,我们经常这样使用:从一个字符串中查找指定子串的位置.例如: SQL> select instr('Oracle','or') position ...

  3. Oracle instr

    instr函数 instr函数在Oracle/PLSQL中是返回要截取的字符串在源字符串中的位置.instr是一个非常好用的字符串处理函数,几乎所有的字符串分隔都用到此函数. 作    用    返回 ...

  4. mysql 替代Oracle instr

    在迁移项目时遇到的,原项目的数据库使用的Oracle,现在要迁移到MySQL中,而项目中用到了Oracle的instr函数,而MySQL只能查找子串是否在父串中,没法按照出现的次数进行查找. 先来介绍 ...

  5. Oracle instr函数与SqlServer charindex的区别

    INSTR(C1,C2[,I[,J]]) [功能]在一个字符串中搜索指定的字符,返回发现指定的字符的位置; [说明]多字节符(汉字.全角符等),按1个字符计算 [参数] C1 被搜索的字符串      ...

  6. oracle instr函数

    语法:instr( fatherstr, sonstr [, start_position [, matchtimes ] ] ) fatherstr:父字符串.要在此字符串中查找子字符串的位置. s ...

  7. Oracle instr() 字符查找函数

    instr()函数的格式  (俗称:字符查找函数) 格式一:instr( string1, string2 )    /   instr(源字符串, 目标字符串) 格式二:instr( string1 ...

  8. Jpa-Spec oracle函数bitand,instr等扩展

    jpa-spec github: https://github.com/wenhao/jpa-spec 使用这个框架可以简化我们拼条件的复杂度,如下代码: public Page<Person& ...

  9. Oracle/Hive/Impala SQL比较1

    5 Function      指数据库内置的function,不讨论UDF.另外,操作符都不比较了,区别不大.   5.1 数学函数 功能 Oracle Hive Impala ABS 绝对值,有 ...

随机推荐

  1. taglib的使用

    使用自定义的taglib可以是我们对页面数据的处理放在后台,不仅使用方便,而且影藏了处理逻辑,也更加的安全. 需要使用到servlet.jar 1.在web-inf下建立taglib.tld文件 &l ...

  2. MySQL innotop实时监测工具

    安装:wget http://innotop.googlecode.com/files/innotop-1.8.0.tar.gz# perl Makefile.PL # make install解决C ...

  3. UIImageView中最容易用错的属性UIContentMode小记

    UIContentMode这东西初学真是各种问题,只能不断尝试,偶然发现网上这张图片,做下记录 还有个UIViewContentModeRedraw,在使用这个设置后,每当图片的bounds就是大小或 ...

  4. Google map实现类似Google earth的图标展开功能

    前言 在Google map的开发时,如果有多个图标重叠在一起,这时下面的图标就点击不到.而在Google Earth中,鼠标一移到上面就会自动弹开,这对于用户而言是十分人性化的一个功能.如下是在Go ...

  5. POJ 1845

    接下来交给大家一个网上查不到的解题方法 题目是酱找出a^b的因子的和答案对9901取模 我们将a可变成这样e1^x1*e2^x2...(ei为素数) 答案就变成这样(e1^0+e1^1...e1^x1 ...

  6. uva 10038 - Jolly Jumpers

    #include <iostream> #include <cstdio> #include <stdlib.h> using namespace std; ], ...

  7. jquery的.detach()方法

    .detach()就是从DOM中删除所有匹配的元素. 与.remove()方法不同的是, 这个方法不会把匹配的元素从jQuery对象中删除,所有绑定的事件.附加的数据等都会保留下来,因而可以在将来再使 ...

  8. memcached学习笔记——存储命令源码分析下篇

    上一篇回顾:<memcached学习笔记——存储命令源码分析上篇>通过分析memcached的存储命令源码的过程,了解了memcached如何解析文本命令和mencached的内存管理机制 ...

  9. centos上安装rabbitmq并且python测试

    把我的阿里云重置了一下,重新安装rabbitmq,看看会出现什么问题. 首先,把erlang环境安装一下,直接 yum list | grep erlang erlang.x86_64 R16B-03 ...

  10. django 模板视图,表单视图,各种视图

    Generic editing views¶ The following views are described on this page and provide a foundation for e ...