LOCATE

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Sintassi

LOCATE(substr, str), LOCATE(substr, str, pos)

Spiegazione

La prima sintassi restituisce la posizione della prima occorrenza della sottostringa substr nella stringa str. La seconda sintassi restituisce la posizione della prima occorrenza della sottostringa substr nella stringa str, a partire dalla posizione pos. Restituisce 0 se substr non è presente in str.

Esempi

MariaDB [(none)]> SELECT LOCATE('bar', 'foobarbar');
+----------------------------+
| LOCATE('bar', 'foobarbar') |
+----------------------------+
|                          4 |
+----------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SELECT LOCATE('My', 'Maria');
+-----------------------+
| LOCATE('My', 'Maria') |
+-----------------------+
|                     0 |
+-----------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SELECT LOCATE('bar', 'foobarbar', 5);
+-------------------------------+
| LOCATE('bar', 'foobarbar', 5) |
+-------------------------------+
|                             7 |
+-------------------------------+
1 row in set (0.00 sec)

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.