contains Function
The contains function indicates whether or not a search string is present inside the source string.
Syntax
The contains function is a Boolean function that performs a simple, literal substring search. The function checks the source string character by character to determine whether the exact sequence of characters from the search string appears anywhere. All characters in the search string are treated as plain text. The contains function does not use regular expressions or SQL wildcards, such as % or _.
returnvalue contains(source, search_string)
source ::= any*
search_string ::= any*
returnvalue ::= booleanSemantics
- source_string
-
The input string to be searched. This argument is implicitly cast to a sequence of strings.
- search_string
-
The string that should be searched in the source. This argument is implicitly cast to a sequence of strings.
- returnvalue
-
Returns true if the search_string is found inside the source string.
Returns false if the search string is not found, or if any argument is an empty sequence or a sequence with more than one item.
Returns NULL if the source or search_string argument is NULL.
Example 12-60 contains Function
In this example, the firstname field values that contain the string "ar" in it is indicated as true.
SELECT firstname, contains(firstname,"ar") FROM usersOutput: +-----------+----------+
| firstname | Column_2 |
+-----------+----------+
| John | false |
| Peter | false |
| Mary | true |
+-----------+----------+