Home  >  Article  >  Database  >  How do the MySQL FIELD() and ELT() functions complement each other?

How do the MySQL FIELD() and ELT() functions complement each other?

PHPz
PHPzforward
2023-08-24 11:25:021413browse

MySQL FIELD() 和 ELT() 函数如何互补?

Judging from the working principles of these two functions, we can say that the two complement each other. In fact, we know that the FIELD() function returns the index number of the string from the string list when providing a string as a parameter, while the ELT() function returns the character from the string list when providing the index number as a parameter. string. In the example below, we have applied both functions on the same string, which will demonstrate the concept -

Example

mysql> SELECT ELT(4, 'Ram','is','good','boy')As Result;

+--------+
| Result |
+--------+
| boy    |
+--------+

1 row in set (0.00 sec)

mysql> SELECT FIELD('boy', 'Ram','is','good','boy')As Result;

+--------+
| Result |
+--------+
|      4 |
+--------+

1 row in set (0.00 sec)

As can be seen from the above result set, a Take an index number as an argument and a string as output, and the other one takes a string as argument and an index number as output. Therefore, they are complementary to each other.

The above is the detailed content of How do the MySQL FIELD() and ELT() functions complement each other?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete