Collections:
FIELD() - Find String in String List
How to find a string in a given string list using the FIELD() function?
✍: FYIcenter.com
FIELD(str, str1, str2, ...) is a MySQL built-in function that
searches for a string in a given string list.
For example:
SET @obj = 'Apple'; SELECT FIELD(@obj, 'Orange', 'Banana', 'Apple'); -- +------------------------------------------+ -- | FIELD(@obj, 'Orange', 'Banana', 'Apple') | -- +------------------------------------------+ -- | 3 | -- +------------------------------------------+
Reference information of the FIELD() function:
FIELD(str, str1, str2, ...): idx Returns the index (position) of str in the str1, str2, str3, ... list. Returns 0 if str is not found. If all arguments to FIELD() are strings, all arguments are compared as strings. If all arguments are numbers, they are compared as numbers. Otherwise, the arguments are compared as double. If str is NULL, the return value is 0 because NULL fails equality comparison with any value. Arguments, return value and availability: str: Required. The string to search for in the string list. str1, str2, ...: One or more strings to form the string list. idx: Return value. The index of the string list where the given is found. Available since MySQL 4.0.
Related MySQL functions:
⇒ FIND_IN_SET() - Find Substring in List String
⇐ ELT() - String at Given Index
2023-11-12, 1352🔥, 0💬
Popular Posts:
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...
How to download and install Microsoft .NET Framework Version 2.0 in SQL Server? .NET Framework Versi...
How To Drop an Index in Oracle? If you don't need an existing index any more, you should delete it w...
What Happens If the UPDATE Subquery Returns Multiple Rows in MySQL? If a subquery is used in a UPDAT...
How To Insert New Line Characters into Strings in SQL Server Transact-SQL? If you want to break a st...