Mysql
 SQL >> Database >  >> RDS >> Mysql

Come funziona la funzione SUBSTR() in MySQL

La funzione SUBSTR() di MySQL restituisce una sottostringa a partire da una posizione specificata. SUBSTR() e MID() sono sinonimi di SUBSTRING().

Sintassi

SUBSTR(str,pos)
SUBSTR(str FROM pos)
SUBSTR(str,pos,len)
SUBSTR(str FROM pos FOR len)

str è la stringa, pos è la posizione iniziale e len è il numero facoltativo di caratteri da restituire.

Esempi

SELECT SUBSTR('I play the drums', 3); restituisce play the drums.

SELECT SUBSTR('I play the drums' FROM 3); restituisce lo stesso risultato usando la sintassi SQL standard.

SELECT SUBSTR('I play the drums', 3, 4); restituisce play.

SELECT SUBSTR('I play the drums' FROM 3 FOR 5); restituisce play.