REGEXP_INSTR函数让你搜索一个正則表達式模式字符串。

函数使用输入字符集定义的字符进行字符串的计算。

它返回一个整数,指示開始或结束匹配的子位置。这取决于return_option參数的值。假设没有找到匹配。则函数返回0。

语法

Oracle数据库中的REGEXP_INSTR函数的语法是:

REGEXP_INSTR (source_char, pattern [, position [, occurrence [, return_option [, match_parameter ] ] ]  ] )

參数

source_char

搜索值的字符表达式,能够是不论什么数据类型CHAR,VARCHAR2,NCHAR,NVARCHAR2,CLOB或NCLOB的。

pattern

正則表達式

Value Description
^ Matches the beginning of a string. If used with a match_parameter of ‘m’, it matches the start of a line anywhere within expression.
$ Matches the end of a string. If used with a match_parameter of ‘m’, it matches the end of a line anywhere within expression.
* 匹配零个或多个.
+ 匹配一个或多个出现.
? 匹配零次或一次出现.
. 匹配不论什么字符。除了空.
| Used like an "OR" to specify more than one alternative.
[ ] Used to specify a matching list where you are trying to match any one of the characters in the list.
[^ ] Used to specify a nonmatching list where you are trying to match any character except for the ones in the list.
( ) Used to group expressions as a subexpression.
{m} Matches m times.
{m,} Matches at least m times.
{m,n} Matches at least m times, but no more than n times.
\n n is a number between 1 and 9. Matches the nth subexpression found within ( ) before encountering \n.
[..] Matches one collation element that can be more than one character.
[::] Matches character classes.
[==] Matches equivalence classes.
\d 匹配一个数字字符.
\D 匹配一个非数字字符.
\w 匹配包含下划线的不论什么单词字符.
\W 匹配不论什么非单词字符.
\s 匹配不论什么空白字符,包含空格、制表符、换页符等等.
\S 匹配不论什么非空白字符.
\A Matches the beginning of a string or matches at the end of a string before a newline character.
\Z Matches at the end of a string.
*? Matches the preceding pattern zero or more occurrences.
+? Matches the preceding pattern one or more occurrences.
?? Matches the preceding pattern zero or one occurrence.
{n}? Matches the preceding pattern n times.
{n,}?

Matches the preceding pattern at least n times.
{n,m}?

Matches the preceding pattern at least n times, but not more than m times.

position

可选。

搜索在字符串中的開始位置。假设省略。则默觉得1。这是字符串中的第一个位置。

occurrence

可选。它是模式字符串中的第n个匹配位置。假设省略,默觉得1。

return_option

可选 指定Oracle返回的位置:

假设指定0,那么Oracle将返回出现的第一个字符的位置。这是默认的。

假设指定1,则Oracle返回字符之后发生的位置。

match_parameter

可选。它同意你改动REGEXP_INSTR功能匹配的行为。

它能够是以下的组合:

Value Description
‘c’ 区分大写和小写的匹配.
‘i’ 不区分大写和小写的匹配.
‘n’ Allows the period character (.) to match the newline character. By default, the period is a wildcard.
‘m’ expression is assumed to have multiple lines, where ^ is the start of a line and $ is the end of a line, regardless of the position of those characters in expression. By default, expression is assumed to be a single line.
‘x’ Whitespace characters are ignored. By default, whitespace characters are matched like any other character.

Examples 匹配单个字符

以下看一个最简单的情况。找到字符串中的第一个”e”字的位置。

SELECT REGEXP_INSTR ('hello itmyhome', 'e')
FROM dual; -- Result: 2

以下这个样例给出一个字符串。 “1”为開始位置 “2”是搜索第二个匹配的,”0”是return_option 返回出现的第一个字符位置

“c”是区分大写和小写 ,所以将返回13

SELECT REGEXP_INSTR ('my is itMyhome', 'm', 1, 2, 0, 'c')
FROM dual; -- Result: 13

Examples 匹配多个字符

我们将使用REGEXP_INSTR函数来匹配多字符模式。

SELECT REGEXP_INSTR ('World filled with love', 'with', 1, 1, 0, 'i')
FROM dual;

这个样例将字符串中返回’with’的第一次出现,它将匹配一个词组。

我们能够改变搜索的開始位置,以便我们运行搜索从字符串的中间開始。

For example:

SELECT REGEXP_INSTR ('my name is itmyhome', 'my', 10, 1, 0, 'i')
FROM dual;

这个样例将開始搜索”my”在字符串中的位置10。

在这样的情况下,在搜索之前。它会跳过字符串中的前9个字符。

Examples 匹配多个备选

以下的样例,我们将使用 | 模式。

该|模式用于像一个”或”指定多个替代方案。

For example:

SELECT REGEXP_INSTR ('Itmyhome', 'a|i|o|e|u')
FROM dual; -- Result: 6

这个样例将返回6,由于它是搜索的第一个元音(a,i,o,e或u)字符串。由于我们没有指定match_parameter值时,

REGEXP_INSTR函数将运行区分大写和小写的搜索,这意味着在”Itmyhome”的’I’将不匹配。

作者:itmyhome

Oracle的REGEXP_INSTR函数简单使用方法的更多相关文章

  1. Oracle的regexp_instr函数简单用法

    REGEXP_INSTR函数让你搜索一个正则表达式模式字符串.函数使用输入字符集定义的字符进行字符串的计算. 它返回一个整数,指示开始或结束匹配的子位置,这取决于return_option参数的值. ...

  2. Oracle的REGEXP_SUBSTR函数简单使用方法

    REGEXP_SUBSTR延伸SUBSTR函数的功能.让你搜索一个正則表達式模式字符串. 这也相似于REGEXP_INSTR.而是返回子字符串的位置,它返回的子字符串本身. 语法 Oracle数据库中 ...

  3. 数据库迁移之从oracle 到 MySQL最简单的方法

    数据库迁移之从oracle 到 MySQL最简单的方法 因工作需要将oracle数据库换到MySQL数据库,数据量比较大,百万级别的数据,表也比较多,有没有一种既快捷又安全的方法呢?答案是肯定的,下面 ...

  4. Oracle的substr函数简单用法与substring区别

    substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('Hello World',0,1) //返回结果为 'H'  *从字符串第一个字符开始截取长度为1的字符串 subst ...

  5. Oracle中Table函数简单应用实例

    说明 表函数可接受查询语句或游标作为输入参数,并可输出多行数据. 该函数可以平行执行,并可持续输出数据流,被称作管道式输出. 应用表函数可将数据转换分阶段处理,并省去中间结果的存储和缓冲表. 优势 1 ...

  6. Oracle的substr函数简单用法

    substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('Hello World',0,1) //返回结果为 'H'  *从字符串第一个字符开始截取长度为1的字符串 subst ...

  7. sort函数简单调用方法

    向量调用sort函数排序,一般有三个参数,即为sort(v.begin(),v.end(),cmp),第三个传入的是比较函数的地址(函数名),决定你比较的性质,运用灵活 #include<ios ...

  8. Oracle的substr函数简单用法(转)

    转:http://www.cnblogs.com/nicholas_f/articles/1526063.html substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('H ...

  9. Oracle的REGEXP_REPLACE函数简单用法

    转载:http://blog.csdn.net/itmyhome1990/article/details/50380718

随机推荐

  1. MyEclipse 2014配置Maven

    1 配置maven (1)下载apache-maven-3.3.3和mvnRespo放在某个路径下,我这里是放在D盘根目录下. (2)修改D:\apache-maven-3.3.3\conf\sett ...

  2. leetcode 282. 给表达式添加运算符

    给定一个仅包含0-9的字符串和一个目标值,返回在数字之间添加了二元运算符(不是一元的) +.-或*之后所有能得到目标值的情况. 例如: "123", 6 -> [" ...

  3. 树莓派学习笔记——GPIO功能学习

    0.前言     树莓派现在越来越火,网上树莓派的资料也越来越多.树莓派的学习可以分为linux系统学习和linux驱动学习,利用树莓派制作LED流水灯应该算是驱动学习吧.树莓派来自国外,国外嵌入式开 ...

  4. 一学就会之ado.net(一)

    ado.net十一组用于和数据源进行交互的面向对象类库.数据源能够是数据库也能够是文本文件.excel表格或者XML文件. 简单来说.ado.net就是与不同的数据源进行交互(增删改查)的. ado. ...

  5. Hadoop-2.4.1学习之怎样确定Mapper数量

    MapReduce框架的优势是能够在集群中并行运行mapper和reducer任务,那怎样确定mapper和reducer的数量呢,或者说怎样以编程的方式控制作业启动的mapper和reducer数量 ...

  6. C++从零实现简单深度神经网络(基于OpenCV)

    代码地址如下:http://www.demodashi.com/demo/11138.html 一.准备工作 需要准备什么环境 需要安装有Visual Studio并且配置了OpenCV.能够使用Op ...

  7. C# 字符串数组转换为整形数组

    /// <summary> /// 字符串数组转换整形数组 /// </summary> /// <param name="Content">字 ...

  8. JavaScript-深入理解JavaScript(一、预编译和执行过程)

    一.预解析 JavaScript 在执行前会进行类似“预解析”的操作:首先会创建一个在当前执行环境下的活动对象, 并将那些用 var 声明的变量.定义的函数设置为活动对象的属性, 但是此时这些变量的赋 ...

  9. 网络请求框架---Volley

    去年的Google I/O大会为android开发者带来了一个网络请求框架,它的名字叫做Volley.Volley诞生的使命就是让Android的网络请求更快,更健壮,而且它的网络通信的实现是基于Ht ...

  10. AL2018届校招笔试——自然语言处理

    [单选40min+在线编程80min] 单选 1.以下进程的哪些行为不会导致操作系统向该进程发送一个信号?() A. 程序终止退出 B. 访问了一个非法的内存地址 C. 一个该程序正在监听的socke ...