MulaiMulai sekarang secara gratis

Replacing and removing substrings

The REPLACE() function is a versatile function that allows you to replace or remove characters from a string. The syntax is as follows:

REPLACE(fieldName, 'searchFor', 'replaceWith')

Where fieldName is the field or string being updated, searchFor is the characters to be replaced, and replaceWith is the replacement substring.

In this exercise, you will look at one specific value in the countries table and change up the format by using a few REPLACE() functions.

Latihan ini adalah bagian dari kursus

Reporting in SQL

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

SELECT 
	region, 
    -- Replace all '&' characters with the string 'and'
    ____ AS character_swap,
    -- Remove all periods
    ____ AS character_remove
FROM countries
WHERE region = 'LATIN AMER. & CARIB'
GROUP BY region;
Edit dan Jalankan Kode