In article Teradata SQL - Use OREPLACE to Replace or Remove Characters, it shows how to use OREPLACE function in Teradata to replace or remove strings. This page will show one more alternative way of doing that using regular expressions.

Remove spaces using OREPLACE

select oreplace('Kontext is a website for data engineers.',' ', '')

You can also use latin ASCII number as search or replace string. CHR function returns the Latin ASCII character given a numeric code value.

select oreplace('Kontext is a website for data engineers.',CHR(32), '')

The ASCII decimal number for space is 32 thus the above code snippet will return the same results.

Remove tabs using OREPLACE

select oreplace('There is a tab in  between.',CHR(9), '')

Remove spaces using REGEXP_REPLACE

You can also use regular expressions to remove certain characters.

select REGEXP_REPLACE('Kontext is a website for data engineers.','\s', '')

In the above code snippet, regular expression \s matches with all the spaces. 

Replace only at least two consecutive spaces

select REGEXP_REPLACE('Kontext   is  a website for data engineers.','[\s]{2,}', '')

Regular expression [\s]{2,} matches at least two space characters; thus only those ones will be replaced. 

Other regular expression functions in Teradata

There are other regular expression related functions in Teradata such as:

  • REGEXP_SUBSTR
  • REGEXP_INSTR
  • REGEXP_SIMILAR
  • REGEXP_SPLIT_TO_TABLE

Refer to the following official page for more details:

Teradata Regular Expression Functions

copyright This page is subject to Site terms.

More from Kontext

local_offer teradata local_offer SQL

visibility 9
thumb_up 0
access_time 11 days ago

The following code snippets show how to use round numbers to hundreds or thousands in Teradata.  warning Alert - The following code snippets are used to round to the smallest hundreds or thousands that is equal or greater than the i...

open_in_new Code snippets

local_offer teradata local_offer SQL

visibility 11
thumb_up 0
access_time 11 days ago

This page shows you how to use LIKE

open_in_new Code snippets

local_offer teradata local_offer SQL

visibility 10
thumb_up 0
access_time 11 days ago

This page shows how to trim or remove leading or/and trailing zeros using Teradata SQL.

open_in_new Code snippets

local_offer teradata local_offer python

visibility 1037
thumb_up 1
access_time 4 months ago

Pandas is commonly used by Python users to perform data operations. In many scenarios, the results need to be saved to a storage like Teradata. This article shows you how to do that easily using JayDeBeApi or  ...

open_in_new Spark + PySpark

comment Comments (0)

comment Add comment

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

No comments yet.

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.


Learn more arrow_forward