Esercitazione MySQL

MySQL HOME Introduzione a MySQL MySQL RDBMS

MySQL SQL

MySQL SQL SELEZIONA MySQL MySQL DOVE MySQL E, O, NON MySQL ORDINA PER MySQL INSERT IN Valori NULL MySQL AGGIORNAMENTO MySQL MySQL DELETE LIMITE MySQL MySQL MIN e MAX MySQL COUNT, MEDIO, SOMMA MySQL MI PIACE Caratteri jolly MySQL MySQL IN MySQL TRA alias MySQL MySQL si unisce MySQL INNER JIN MySQL ha lasciato il join MySQL GIUSTO UNISCITI MySQL CROSS JIN MySQL Self Join MySQL UNION MySQL GRUPPO PER MySQL AVENDO MySQL ESISTE MySQL QUALSIASI, TUTTO SELEZIONA INSERTO MySQL CASO MySQL Funzioni null di MySQL Commenti MySQL Operatori MySQL

Database MySQL

MySQL Crea DB MySQL Drop DB MySQL Crea tabella MySQL Drop Table MySQL Alter tabella Vincoli MySQL MySQL non nullo MySQL unico Chiave primaria MySQL Chiave esterna MySQL Controllo MySQL MySQL predefinito MySQL Crea indice Incremento automatico di MySQL Date MySQL Viste MySQL

Riferimenti MySQL

Tipi di dati MySQL Funzioni MySQL

Esempi MySQL

Esempi MySQL Quiz MySQL Esercizi MySQL

Funzione MySQL SUBSTRING()

❮ Funzioni MySQL

Esempio

Estrai una sottostringa da una stringa (inizia dalla posizione 5, estrai 3 caratteri):

SELECT SUBSTRING("SQL Tutorial", 5, 3) AS ExtractString;

Definizione e utilizzo

La funzione SUBSTRING() estrae una sottostringa da una stringa (a partire da qualsiasi posizione).

Nota: le funzioni SUBSTR() e MID() equivalgono alla funzione SUBSTRING().

Sintassi

SUBSTRING(string, start, length)

O:

SUBSTRING(string FROM start FOR length)

Valori dei parametri

Parameter Description
string Required. The string to extract from
start Required. The start position. Can be both a positive or negative number. If it is a positive number, this function extracts from the beginning of the string. If it is a negative number, this function extracts from the end of the string
length Optional. The number of characters to extract. If omitted, the whole string will be returned (from the start position)

Dettagli tecnici

Funziona in: Da MySQL 4.0

Altri esempi

Esempio

Estrai una sottostringa dal testo in una colonna (inizia dalla posizione 2, estrai 5 caratteri):

SELECT SUBSTRING(CustomerName, 2, 5) AS ExtractString
FROM Customers;

Esempio

Estrarre una sottostringa da una stringa (iniziare dalla fine, in posizione -5, estrarre 5 caratteri):

SELECT SUBSTRING("SQL Tutorial", -5, 5) AS ExtractString;

❮ Funzioni MySQL