Skip to Content
Date, Number, and String Functions
Strings II

Another useful string function in SQL is REPLACE():


The function returns the string string with all occurrences of the string from_string replaced by the string to_string.

For example in baked_goods, there is a column named ingredients. The ingredients strings are formatted with underscores, such as baking_soda and vanilla_extract. To make these values more readable, we might like to replace the underscores with spaces. We can do so by using the following query:

SELECT id, REPLACE(ingredients,'_',' ') as item_ingredients from baked_goods;



Any time enriched_flour appears in the ingredients list, we’d like to replace it with just flour.

Apply this transformation and be sure to rename the column item_ingredients.

Folder Icon

Sign up to start coding

Already have an account?