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

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

PHPz
Release: 2023-08-24 11:25:02
forward
1431 people have browsed it

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template