Oracle instr 及 like
原文: 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的更多相关文章
- Oracle instr用法
1:实现indexOf功能,.从第1个字符开始,搜索第1次出现子串的位置 ,) as i from dual; select instr('oracle','or') as i from dual; ...
- oracle instr函数(oracle 用instr 来代替 like)
oracle instr函数 对于instr函数,我们经常这样使用:从一个字符串中查找指定子串的位置.例如: SQL> select instr('Oracle','or') position ...
- Oracle instr
instr函数 instr函数在Oracle/PLSQL中是返回要截取的字符串在源字符串中的位置.instr是一个非常好用的字符串处理函数,几乎所有的字符串分隔都用到此函数. 作 用 返回 ...
- mysql 替代Oracle instr
在迁移项目时遇到的,原项目的数据库使用的Oracle,现在要迁移到MySQL中,而项目中用到了Oracle的instr函数,而MySQL只能查找子串是否在父串中,没法按照出现的次数进行查找. 先来介绍 ...
- Oracle instr函数与SqlServer charindex的区别
INSTR(C1,C2[,I[,J]]) [功能]在一个字符串中搜索指定的字符,返回发现指定的字符的位置; [说明]多字节符(汉字.全角符等),按1个字符计算 [参数] C1 被搜索的字符串 ...
- oracle instr函数
语法:instr( fatherstr, sonstr [, start_position [, matchtimes ] ] ) fatherstr:父字符串.要在此字符串中查找子字符串的位置. s ...
- Oracle instr() 字符查找函数
instr()函数的格式 (俗称:字符查找函数) 格式一:instr( string1, string2 ) / instr(源字符串, 目标字符串) 格式二:instr( string1 ...
- Jpa-Spec oracle函数bitand,instr等扩展
jpa-spec github: https://github.com/wenhao/jpa-spec 使用这个框架可以简化我们拼条件的复杂度,如下代码: public Page<Person& ...
- Oracle/Hive/Impala SQL比较1
5 Function 指数据库内置的function,不讨论UDF.另外,操作符都不比较了,区别不大. 5.1 数学函数 功能 Oracle Hive Impala ABS 绝对值,有 ...
随机推荐
- C#高级知识点概要(1) - 委托和事件
本文目录: 委托 委托的简单使用 用委托实现插件式编程 多播委托 静态方法和实例方法对于委托的区别 泛型委托 Func 和 Action 委托 委托的兼容 事件 事件的基本使用 事件的标准模式 委托 ...
- h5标签canvas关于getImageData跨域的问题
h5标签canvas关于getImageData跨域的问题 在学习h5的时候,canvas标签中getImageData()报错:security error! 具体代码如下(chrome浏览器): ...
- 一些小trick~
做质因子分解的时候将先打素数表会节省很多时间
- Struts2 过滤器与拦截器
学习Struts2时,发现有过滤器和拦截器,他们貌似都是一样的功能,但是为什么会有2个不同的名称呢?肯定是有区别的,所以打算自己整理一下. 过滤器,是在java web中,你传入的request,re ...
- Html5 学习之 Html5功能判断插件 Modernizr
---恢复内容开始--- Modernizr 浏览器对HTML5和CSS3开发的功能检测类库 由于当前用户使用的浏览器版本较多,对H5和CSS3的支持也各不相同.前端的开发者,在使用一些新的特性的时候 ...
- C#实现窗体间的通信
以下将窗体间的几种通信实现方式做一下罗列:首先新建一个窗体Form1,在其中放置一个Textbox.Button控件.再新建一个窗体Form2,其上放置一个Button控件.具体代码示例如下: //F ...
- python学习第七天 -- dict 和set
今天主要学习关于python 的dict(全称dictionary)和set.dict的用法跟javascript 中map表类似,key + value结构语言.而set,准确来说,只是key的集合 ...
- C语言初学 测定各数据类型的长度
#include<stdio.h> #include<stdlib.h> int main() { int a,b; int i=0; printf("char:%d ...
- C 带指针样式的时钟
#include <stdio.h> #include <malloc.h>#include<graphics.h>#include<conio.h> ...
- Cassandra笔记--2. 安装
1. 从apache官网下载Cassandra,我用的版本是2.1.8.压缩包解压,这里的目录是D:\cassandra\apache-cassandra-2.1.8 2. 配置环境变量 添加环境变 ...