REPLACEfunzione - Amazon Redshift

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à.

REPLACEfunzione

Sostituisce tutte le occorrenze di un insieme di caratteri all'interno di una stringa esistente con altri caratteri specificati.

REPLACEè simile a TRANSLATEfunzione and theREGEXPfunzione _ REPLACE, tranne per il fatto che TRANSLATE effettua più sostituzioni di un singolo carattere e REGEXP _ REPLACE consente di cercare in una stringa 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 o VARCHAR da cercare in ricerca

old_chars

La stringa CHAR o VARCHAR da sostituire.

new_chars

Nuova stringa CHAR o VARCHAR che sostituisce old_string.

Tipo restituito

VARCHAR

Se old_chars o new_chars è NULL, il risultato è NULL.

Esempi

L'esempio seguente utilizza i dati della CATEGORY tabella del database di esempio. TICKIT Per ulteriori informazioni, consulta Database di esempio.

Per convertire la stringa Shows Theatre in un CATGROUP campo, utilizzate 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 | +-------+----------+----------+