当前位置:操作系统 > Unix/Linux >>

[每日一题] OCP1z0-047 :2013-08-21正则表达式---REGEXP_INSTR

[每日一题] OCP1z0-047 :2013-08-21正则表达式---REGEXP_INSTR
 
 
正确答案:D
 
根据题意WHERE条件的意思是“street_address”列中第一个位置不为字符(即为数字),执行以上SQL语句,如下结果:
 
[html] 
hr@MYDB> SELECT street_address  
  2  FROM locations  
  3  WHERE  
  4  REGEXP_INSTR(street_address,'[^[:alpha:]]')=1;  
  
STREET_ADDRESS  
----------------------------------------  
1297 Via Cola di Rie  
93091 Calle della Testa  
2017 Shinjuku-ku  
9450 Kamiya-cho  
2014 Jabberwocky Rd  
2011 Interiors Blvd  
2007 Zagora St  
2004 Charade Rd  
147 Spadina Ave  
6092 Boxwood St  
40-5-12 Laogianggen  
1298 Vileparle (E)  
12-98 Victoria Street  
198 Clementi North  
8204 Arthur St  
9702 Chester Road  
20 Rue des Corps-Saints  
  
17 rows selected.  

 

 
REGEXP_INSTR函数 
语法
说明
REGEXP_INSTR(source_string,pattern
[, start_position
[, occurrence
[, return_option
[, match_parameter]]]])
该函数查找pattern,并返回该模式的第一个位置。您可以随意指定您想要开始搜索的 start_position。 occurrence 参数默认为 1,除非您指定您要查找接下来出现的一个模式。return_option 的默认值为 0,它返回该模式的起始位置;值为 1 则返回符合匹配条件的下一个字符的起始位置。
 
'^' 匹配输入字符串的开始位置,在方括号表达式中使用,此时它表示不接受该字符集合。
[[:alpha:]] 任何字母。
[^[:alpha:]] 非任何字母
如下操作:
[html] 
gyj@MYDB> select REGEXP_INSTR('guoyJoe','[^[:alpha:]]') from dual;  
  
REGEXP_INSTR('GUOYJOE','[^[:ALPHA:]]')  
--------------------------------------  
                                     0  
gyj@MYDB> select REGEXP_INSTR('1guoyJoe','[^[:alpha:]]') from dual;  
  
REGEXP_INSTR('1GUOYJOE','[^[:ALPHA:]]')  
---------------------------------------  
                                       

 

 
参考官方文档:
 
 
Examples
The following example examines the string, looking for occurrences of one or more non-blank characters. Oracle begins searching at the first character in the string and returns the starting position (default) of the sixth occurrence of one or more non-blank characters.
[html] 
gyj@MYDB> SELECT  
  2    REGEXP_INSTR('500 Oracle Parkway, Redwood Shores, CA',  
  3                 '[^ ]+', 1, 6) "REGEXP_INSTR"  
  4    FROM DUAL;  
  
  
REGEXP_INSTR  
------------  
          37  

 

 
The following example examines the string, looking for occurrences of words beginning with s, r, or p, regardless of case, followed by any six alphabetic characters. Oracle begins searching at the third character in the string and returns the position in the string of the character following the second occurrence of a seven-letter word beginning with s, r, or p, regardless of case.
[html] 
gyj@MYDB> SELECT  
  2    REGEXP_INSTR('500 Oracle Parkway, Redwood Shores, CA',  
  3                 '[s|r|p][[:alpha:]]{6}', 3, 2, 1, 'i') "REGEXP_INSTR"  
  4    FROM DUAL;  
  
  
REGEXP_INSTR  
------------  
          28  

 

 
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,