MariaDB: FIELD Function
This MariaDB tutorial explains how to use the MariaDB FIELD function with syntax and examples.
Description
The MariaDB FIELD function returns the position of a value in a list of values (val1, val2, val3, ...).
Syntax
The syntax for the FIELD function in MariaDB is:
FIELD( value, val1, val2, val3, ... )
Parameters or Arguments
- value
- The value to find.
- val1, val2, val3, ...
- A list of values that is to be searched.
Note
- If value is not found in the list of values (val1, val2, val3, ...), the FIELD function will return 0.
- If value is NULL, the FIELD function will return 0.
- If all arguments in the FIELD function are string values, the find is performed as string values.
- If all arguments in the FIELD function are numeric values, the find is performed as numeric values.
Applies To
The FIELD function can be used in the following versions of MariaDB:
- MariaDB 10
Example
Let's look at some MariaDB FIELD function examples and explore how to use the FIELD function in MariaDB.
For example:
SELECT FIELD('The', 'Tech', 'On', 'The', 'Net'); Result: 3 SELECT FIELD('THE', 'Tech', 'On', 'The', 'Net'); Result: 4 SELECT FIELD(3, 1, 2, 3, 4); Result: 3 SELECT FIELD('T', 'C', 'B'); Result: 0 SELECT FIELD(NULL, 'z', 'y', 'x'); Result: 0 SELECT FIELD('Z', NULL); Result: 0
Advertisements