MySQL8 FIELD() Functions – String Functions

MySQL FIELD() Functions: Syntax

FIELD ( searchString, string1, string2, string3, ….. );

MySQL FIELD() Functions: Description

Field() functions search for the specified string in the strings arguments. If the search string is found then its index position will be returned else 0 will be returned.

If all arguments 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 searchString is NULL, the return value is 0 because NULL fails equality comparison with any value.

Note : FIELD() is the complement of ELT().

MySQL FIELD() Functions: Parameter

[table caption=”” width=”100%” colwidth=”15%|30%|55%” colalign=”left|left|left”]
Name, Required /Optional, Description
searchString, Required, The search string in the list.
string1, Required, It is must.
string2 , Optional, It is optional.
string3 , Optional, It is optional.

[/table]


MySQL FIELD() Functions: Output

[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Returns,
index (position), It returns index position of searchString in the list.
0, if search string is not found.
0, If search string is NULL.
[/table]


MySQL FIELD() Functions: Available from

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 4.0
[/table]


MySQL FIELD() Functions: Example 1

mysql>  SELECT FIELD('.net','Tutorial', 'mines', '.net') ;
+--------------------------------------------+
| FIELD('.net','Tutorial', 'mines', '.net') |
+--------------------------------------------+
| 3                           |
+--------------------------------------------+
1 row in set (0.00 sec)

MySQL FIELD() Functions: Example 2

mysql> SELECT FIELD('www','Tutorial', 'mines', '.net') ;
+------------------------------------+
| FIELD('www','Tutorial', 'mines', '.net') |
+------------------------------------+
| 0                               |
+------------------------------------+

MySQL FIELD() Functions: Example 3

mysql>  SELECT FIELD('.net','11', '22', '33') ;
+------------------------------------+
| FIELD('.net','11', '22', '33') ; |
+------------------------------------+
| 0                              |
+------------------------------------+

MySQL FIELD() Functions: Example 4

mysql>  SELECT FIELD('NULL','11', '22', '33') ;
+------------------------------------+
| FIELD('NULL','11', '22', '33') ; |
+------------------------------------+
| 0                              |
+------------------------------------+

MySQL FIELD() Functions: Example 5

mysql>  SELECT FIELD(22, 11, 22, 33) ;
+------------------------------------+
| FIELD(22, 11, 22, 33) ; |
+------------------------------------+
| 2                              |
+------------------------------------+

MySQL FIELD() Functions: Example 6

mysql>  SELECT FIELD('6','') ;
+------------------------------------+
| FIELD('6','') |
+------------------------------------+
| 0                              |
+------------------------------------+

See all MySQL String functions MySQL 8 String Functions.


Related articles : ELT(), CONCAT(), CONCAT_WS() ,LOWER(), UPPER(), LTRIM(), RTRIM().


PHP Related articles : IMPLODE(), STRRCHR(), STRRPOS(), PHP STRING FUNCTIONS(), STRRIPOS().

You may also like...