FIELD

2023-07-28 02:55:42  Updated

Syntax

FIELD(str,str1,str2,str3,...)

Purpose

FIELD() returns the index position (starting from str1) of str in the list of str1, str2, str3, ... If str is not found, 0 is returned.

If all FIELD() parameters are strings, all parameters are compared as strings. If all parameters are numbers, the parameters are compared as numbers. Otherwise, the parameters are compared as DOUBLE values.

If str is NULL, the return value is 0. This is because NULL is neither equal to nor unequal to any value. FILED() is the complement of ELT().

Examples

obclient> SELECT FIELD('abc','abc1','abc2','abc','abc4','abc'), FIELD(NULL, 'null1', NULL);
+-----------------------------------------------+----------------------------+
| FIELD('abc','abc1','abc2','abc','abc4','abc') | FIELD(NULL, 'null1', NULL) |
+-----------------------------------------------+----------------------------+
|                                             3 |                          0 |
+-----------------------------------------------+----------------------------+
1 row in set

Contact Us