Home > Database > Oracle > body text

How to determine whether two strings are contained in oracle

下次还敢
Release: 2024-05-08 19:00:25
Original
845 people have browsed it

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

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>
Copy after login

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>
Copy after login

Result:

<code>7</code>
Copy after login

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>
Copy after login

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>
Copy after login

Result:

<code>包含</code>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!