ID EN
String Functions and Operators

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

MySQL 8.4 🇮🇩 Bahasa Indonesia

Mengembalikan indeks (posisi) str dalam daftar str1, str2, str3, .... Mengembalikan 0 jika str tidak ditemukan.

Syntax

MYSQL
SELECT FIELD('Bb', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
2
SELECT FIELD('Gg', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
0

Contoh

Example

If all arguments to FIELD() 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.

MYSQL
SELECT FIELD('Bb', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
2
SELECT FIELD('Gg', 'Aa', 'Bb', 'Cc', 'Dd', 'Ff');
0