OREPLACE Function Examples | Teradata Vantage - 17.10 - Example - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1145-171K
Language
English (United States)

The following query returns the string 'TD14.0 is the current version'. The string '13.1' in the source string was replaced by the string '14.0'.

   SELECT OREPLACE('TD13.1 is the current version', '13.1', '14.0'); 

The following query returns the string 'This chair is a brown chair'. Both occurrences of the search string 'bag' in the source string were replaced by the string 'chair'.

   SELECT OREPLACE('This bag is a brown bag', 'bag', 'chair'); 

The following query returns the string 'TD13.1 is the current version'. The source string is returned unchanged since the search string is NULL. The result would be the same if the search string is an empty string or a string that has no matches in the source string.

   SELECT OREPLACE('TD13.1 is the current version', NULL, '14.0'); 

The following query returns the string 'We removed the extra word'. The occurrence of the search string 'superfluous' was removed from the source string.

   SELECT OREPLACE('We removed the superfluous extra word',
      'superfluous', NULL); 

The result set from the following query will have an ADDRESS column that is the concatenation of the ADDRESS1 and ADDRESS2 columns from the CUSTOMER table, with every occurrence of 'st.' replaced with ' street'.

   SELECT OREPLACE(ADDRESS1||ADDRESS2, ' st.', ' street') AS ADDRESS
      from CUSTOMER;