36.Oracle数据库SQL开发之 使用简单函数——使用单行函数正则表达式函数

36.Oracle数据库SQL开发之 使用简单函数——使用单行函数正则表达式函数

欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/49722999

这些函数可以在字符串中搜索字符模式。

1.  REGEXP_LIKE()

REGEXP_LIKE(x,pattern [,match_option])用于在x中查找pattern参数中定义的正则表达式。

可以设置为下面几个字符之一:

‘c’,说明在匹配时区分大小写

‘I’,说明在匹配时不区分大小写

‘n’,允许使用可以匹配任意字符的操作符

‘m’,将x作为一个包含多行的字符串

store@PDB1> select customer_id,first_name,last_name,dobfrom customers where regexp_like(to_char(dob,'YYYY'),'^196[5-8]$');

 

CUSTOMER_ID FIRST_NAME LAST_NAME  DOB

----------- ---------- ---------- ---------

           1 John      Brown   01-JAN-65

           2 Cynthia   Green     05-FEB-68

检索名字以J或j开头的顾客。

例如:

store@PDB1> selectcustomer_id,first_name,last_name,dob from customers whereregexp_like(first_name,'^j','i');

 

CUSTOMER_ID FIRST_NAME LAST_NAME  DOB

----------- ---------- ---------- ---------

           1 John      Brown   01-JAN-65

2.  REGEXP_INSTR()

REGEXP_INSTR(x,pattern [,start [,occurrence[,return_option [, match_option]]]]) 用于在x中查找pattern,返回pattern出现的位置。

例如:

store@PDB1> select regexp_instr('But,soft! Whatlight through yonder window breaks?', 'l[[:alpha:]]{4}') as result from dual;

 

   RESULT

----------

         16

store@PDB1> select regexp_instr('But, soft! Whatlight through yonder window breaks?','o',10,2) as result from dual;

 

   RESULT

----------

         32

3.  REGEXP_REPLACE()

REGEXP_REPLACE(x,pattern [,replace_string[,start [,occurrence[, match_option]]]])用于在x 中查找pattern,将其替换为replace_string.

例如:

store@PDB1> select regexp_replace('But, soft! Whatlight through yonder window breaks?','l[[:alpha:]]{4}','sound') as result fromdual;

 

RESULT

---------------------------------------------------

But, soft! What sound through yonder windowbreaks?

4.  REGEXP_SUBSTR()

REGEXP_SUBSTR(x,pattern[, start [, occurrence[, match_option]]]) 用于在x中查找匹配pattern的字符串,开始位置由start指定。

store@PDB1> select regexp_substr('But, soft! Whatlight through yonder window breaks?','l[[:alpha:]]{4}') as result from dual;

RESUL

-----

light

5.  REGEXP_COUNT()

REGEXP_COUNT()是11g新增加的一个函数。

REGEXP_COUNT(x,pattern[, start[,match_option]])用于在x中查找pattern,并返回pattern在x中出现的次数。

例如:

store@PDB1> select regexp_count('But, soft! Whatlight through yonder window softly breaks?','s[[:alpha:]]{3}') as result fromdual;

   RESULT

----------

          2

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值