Evaluate the following SQL statement:
SELECT street_address
FROM locations WHERE REGEXP_INSTR(street_address,'[^[:alpha:]]') = 1;
Which statement is true regarding the output of this SQL statement?
A. It would display all the street addresses that do not have a substring
'alpha'.
B. It would display all the street addresses where the first character is
a special character.
C. It would display all the street addresses where the first character is
a letter of the alphabet.
D. It would display all the street addresses where the first character is
not a letter of the alphabet.
Answer: D
REGEXP_INSTR 有6个参数:
第一个是输入的字符串 第二个是正则表达式
第三个是标识从第几个字符开始正则表达式匹配。(默认为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.
SQL> select REGEXP_I NSTR('1234aa','[:alpha:]') from dual; 第一个字母的位置
REGEXP_INSTR('1234AA','[:ALPHA:]')
----------------------------------
5
SQL> select REGEXP_INSTR('1234aa','[^[:alpha:]]') from dual; 第一个非字母的位置
REGEXP_INSTR('1234AA','[^[:ALPHA:]]')
-------------------------------------
1
做题的是注意细节,有[^表示非的意思