Átomo
74Rr
Texto · SQL

REGEXP_REPLACE

Abrir na tabela

Definição

Substitui trechos que casam com uma expressão regular. Serve para limpeza de texto mais complexa.

No PostgreSQL, acrescente o argumento 'g' para substituir todas as ocorrências.

Exemplos

1. Manter só dígitos
SELECT REGEXP_REPLACE(phone, '[^0-9]', '') AS phone
FROM stg_contacts;
2. Reduzir espaços repetidos
SELECT REGEXP_REPLACE(name, ' +', ' ') AS name
FROM stg_customers;
3. Mascarar dados
SELECT REGEXP_REPLACE(tax_id, '[0-9]', '*') AS masked_tax_id
FROM customers;

No mesmo grupo