Categories: MySQL Functions

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().

jyoti rani

Recent Posts

What Is a Progressive Web App? Why Would You Need One?

App usage is growing steadily without showing any signs of slowing down. Hence, it is no surprise that mobile applications…

1 year ago

7 Most Popular Paid Online Advertising Strategy

As the world has grown more digital, businesses have adapted themselves. An effectual adaptation includes online advertising. Offline advertising styles…

1 year ago

The Importance of User-Centered Design in Mobile App Development

Step into a world where apps dance to the user's tune. Picture Instagram, a photo-sharing sensation that swept the globe.…

1 year ago

Healthcare Mobile App Development: A Complete Guide for Founders

COVID-19 has led to a digitalization of lifestyle. As patients are taking their mental and physical health more seriously, healthcare…

1 year ago

Exploring Diverse WordPress Theme Niches: A Comprehensive Guide

Introduction WordPress, an immensely popular content management system (CMS), powers over 40% of the internet. What makes WordPress even more…

1 year ago

8 Awesome Blog Content Ideas for Movers to Skyrocket the SEO

For moving companies trying to capture their market share amidst stiff competition, a tip or two about what they can…

1 year ago