DB2 REPLACE Function: Syntax & Usage Guide

The REPLACE function in DB2 database can be used to replace a substring within a string. Its syntax is as follows:

REPLACE(string, search_string, replacement_string)

Among them:

  1. String: The string that will undergo replacement operations.
  2. search_string: the substring to be replaced.
  3. new_string to be replaced with in the string

For example, if we have a string “Hello World” and we want to replace the “World” with “Universe”, we can use the following SQL statement:

SELECT REPLACE('Hello World', 'World', 'Universe') AS new_string;

This will return the result as “Hello Universe”.

bannerAds