Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SQL FIELD() function


May 16, 2021 SQL


Table of contents


SQL FIELD() function


SQL FIELD() function instance code tutorial

The FIELD() function returns the str of the index (where it started from 1) in str1, str2, str3,... l ist. If str is not found, 0 is returned.

Is to use the first argument str, followed by N string parameters to find, if you find exactly the same string, return its index position

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


The returned index (where it starts from 1) str is in str1, str2, str3,... l ist. If str is not found, 0 is returned.

Example

The string "ej" was found in the second position.

SQL> SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');
+---------------------------------------------------------+
| FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo')          |
+---------------------------------------------------------+
| 2                                                       |
+---------------------------------------------------------+
1 row in set (0.00 sec)