標籤:使用 nvarchar not span 多個 ref value exce star
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函數簡單使用方法