PostgreSQL; MS SQL Server 2012; Oracle 11g; MySQL
CREATE TABLE tabela(email VARCHAR(320));
INSERT INTO tabela VALUES ('[email protected]');
INSERT INTO tabela VALUES ('[email protected]');
UPDATE
tabela
SET
email = replace(email, 'jf.gov.br', 'jf.jus.br');
SELECT email FROM tabela;
SQLFiddle
Note that you do not even need WHERE
because replace will only replace if found.
But if you want you can put in order to avoid " pranks " you can do:
UPDATE
tabela
SET
email = replace(email, 'jf.gov.br', 'jf.jus.br');
SELECT email FROM tabela;
WHERE RIGHT(email,9) = 'jf.gov.br';
SELECT email FROM tabela;
O will be generic and will probably work on most databases. However Oracle 11g would be an example of an exception because, instead of RIGHT(email,9)
you should use substr(email,-9)
.