Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Sostituisce tutte le occorrenze di un insieme di caratteri all'interno di una stringa esistente con altri caratteri specificati.
REPLACE è simile a Funzione TRANSLATE e a Funzione REGEXP_REPLACE, ad eccezione del fatto che TRANSLATE esegue più sostituzioni a carattere singolo e REGEXP_REPLACE consente di cercare una stringa per un modello di espressione regolare, mentre REPLACE sostituisce un'intera stringa con un'altra stringa.
Sintassi
REPLACE(string, old_chars, new_chars)
Argomenti
- stringa
-
La stringa
CHAR
oVARCHAR
da cercare in ricerca - old_chars
-
La stringa
CHAR
oVARCHAR
da sostituire. - new_chars
-
Nuova stringa
CHAR
oVARCHAR
che sostituisce old_string.
Tipo restituito
- VARCHAR
-
Se old_chars o new_chars è
NULL
, il risultato èNULL
.
Esempi
Nell'esempio seguente vengono utilizzati i dati della tabella CATEGORY database di esempio TICKIT. Per ulteriori informazioni, consulta Database di esempio.
Per convertire la stringa Shows
in Theatre
nel campo CATGROUP, utilizza l'esempio seguente.
SELECT catid, catgroup, REPLACE(catgroup, 'Shows', 'Theatre')
FROM category
ORDER BY 1,2,3;
+-------+----------+----------+
| catid | catgroup | replace |
+-------+----------+----------+
| 1 | Sports | Sports |
| 2 | Sports | Sports |
| 3 | Sports | Sports |
| 4 | Sports | Sports |
| 5 | Sports | Sports |
| 6 | Shows | Theatre |
| 7 | Shows | Theatre |
| 8 | Shows | Theatre |
| 9 | Concerts | Concerts |
| 10 | Concerts | Concerts |
| 11 | Concerts | Concerts |
+-------+----------+----------+