regexp_instr

来源:互联网 发布:电子阅览室软件配置 编辑:程序博客网 时间:2024/06/06 21:00

SQL> select *from a98;

ID ADDRESS
---------- ---------------
2 abc1
1 1abc

SQL> select * from a98
2 where regexp_instr (address,'[^[:alpha:]]') = 1;

ID ADDRESS
---------- --------------------
1 1abc

SQL> select * from a98
2 where regexp_instr (address,'[:alpha:]') = 1;

ID ADDRESS
---------- --------------------
2 abc1


= 1 表是匹配第几个字符

REGEXP_INSTR 有6个参数:
第一个是输入的字符串 (上面的字段address) 第二个是正则表达式
第三个是标识从第几个字符开始正则表达式匹配。(默认为1)
第四个是标识第几个匹配组。(默认为1)
第五个是指定返回值的类型,如果该参数为0,则返回值为匹配位置的第一个字符,如果该值为
非0则返回匹配值的最后一个位置。
第六个是是取值范围:
i:大小写不敏感; c:大小写敏感; n:点号 . 不匹配换行符号;
m:多行模式; x:扩展模式,忽略正则表达式中的空白字符。
正则表达式规则: [^. . .] --- A “not equals” bracket expression
| --- Logical OR.
. --- Match any character in the database character set.
$ --- End of line anchor
^ --- Beginning of line anchor.
+ ---Match one or more occurrences of the preceding subexpression.


[^Ale|ax.r$]

[]表示一个字符组,在字符组里,. | $只表是本身的字符,已经不是正则里的元字符了,且^只有在开头,才表示非

[^Ale|ax.r$]这个正则表示的意义是字符串里存在除了A、l、e、|、a 、x、.、r、$之外的字符
------------------------------------------------------------------------------------------------------


select regexp_instr('Alex','[^Ale|ax.r$]') from dual;
REGEXP_INSTR('ALEX','[^ALE|AX.R$]')
-----------------------------------
0
select regexp_instr('Alax','[^Ale|ax.r$]') from dual;
REGEXP_INSTR('ALAX','[^ALE|AX.R$]')
-----------------------------------
0
select regexp_instr('Alxer','[^Ale|ax.r$]') from dual;
REGEXP_INSTR('ALXER','[^ALE|AX.R$]')
------------------------------------
0
select regexp_instr('Alaxendar','[^Ale|ax.r$]') from dual;
REGEXP_INSTR('ALAXENDAR','[^ALE|AX.R$]')
----------------------------------------
6
select regexp_instr('Alexender','[^Ale|ax.r$]') from dual;
REGEXP_INSTR('ALEXENDER','[^ALE|AX.R$]')
----------------------------------------
6


原创粉丝点击