Amazon Redshift non supporterà più la creazione di nuove UDF Python a partire dal 1º novembre 2025. Se desideri utilizzare le UDF Python, creale prima di tale data. Le UDF Python esistenti continueranno a funzionare normalmente. Per ulteriori informazioni, consulta il post del blog
Funzione REPLACE
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
- string
-
La stringa
CHARoVARCHARda cercare in ricerca - old_chars
-
La stringa
CHARoVARCHARda sostituire. - new_chars
-
Nuova stringa
CHARoVARCHARche 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 | +-------+----------+----------+