Tuesday 10 July 2012

How to replace a string in a column using Teradata functions?


How to replace a string in a column using Teradata functions?

We can use the Oreplace function in Teradata.

Oreplace function usage:

Syntax :- OREPLACE(Column_name, ’Old_String’, ‘New_String’)
Functionality :- This function is used to replace any particular character or string with another character or string without the concern of how many times the string is coming in the particular value.
Example :-
Suppose we have values in table exmpl like this
Column1 Column2
abc$xyz 10
xz$saas 20
$ads$asd 30
man$all 40
as$fsadf$ 50
Now suppose we want to fetch the data and in the report I want to change ‘$’ character with ‘@’. So we can write as
Select
OREPLACE(Column1,’$’,’@’) , Column2
From exmpl;
Then the output will be like this
Column1 Column2
abc@xyz 10
xz@saas 20
@ads@asd 30
man@all 40
as@fsadf@ 50

No comments:

Post a Comment

Please share your thoughts and let us know the topics you want covered