In Oracle, you can use the nested INSTR function to determine whether a string contains two substrings at the same time: when INSTR(string1, string2a) is greater than 0 and INSTR(string1, string2b) is greater than 0, it contains ; Otherwise it is not included.
How to determine whether two strings are contained in Oracle
In Oracle database, you can use INSTR
Function to determine whether a string contains another string. INSTR
The function returns the position of the first matching substring in the first string. If the substring is not in the first string, 0 is returned.
Syntax:
<code class="sql">INSTR(string1, string2)</code>
Parameters:
string1
: Characters to search for String string2
: The substring to be found Example:
Judge string "Hello, world!"
Whether it contains the substring "world"
:
<code class="sql">SELECT INSTR('Hello, world!', 'world') FROM dual;</code>
Result:
<code>7</code>
This means the substring "world "
starts from the 7th character of the string "Hello, world!"
.
Determine whether two strings are included in another string:
To determine whether two strings are included in another string, you can Using nested INSTR
Function:
<code class="sql">SELECT CASE WHEN INSTR(string1, string2a) > 0 AND INSTR(string1, string2b) > 0 THEN '包含' ELSE '不包含' END FROM dual;</code>
Parameters:
string1
: The string to search for string2a
: The first substring to be found string2b
: The second substring to be found Example:
Determine whether the string "The quick brown fox jumps over the lazy dog"
contains the substring "quick"
and "lazy"
:
<code class="sql">SELECT CASE WHEN INSTR('The quick brown fox jumps over the lazy dog', 'quick') > 0 AND INSTR('The quick brown fox jumps over the lazy dog', 'lazy') > 0 THEN '包含' ELSE '不包含' END FROM dual;</code>
Result:
<code>包含</code>
The above is the detailed content of How to determine whether two strings are contained in oracle. For more information, please follow other related articles on the PHP Chinese website!