Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10545
  • Last Modified:

Teradata String Replace Function

Hi,

I have a column with values such as:

A.B.C
1.2.3

It is a varchar column. I would like to strip out all periods from it. Is there a Teradata function or set of functions that can help me do that?

Thanks.
0
infa008
Asked:
infa008
4 Solutions
 
Richard QuadlingSenior Software DeveloperCommented:
As you've probably worked out, there is no REPLACE function.

The best I could find was at http://www.teradataforum.com/teradata/20020729_174333.htm

Not exactly pretty, but doable.

Another option, depending upon the amount of data, would be to export it to a file, do a simple search/replace, save it and re-import it.

0
 
seenallCommented:
From the forums also - a bit more chewy example here - this might  be at least more flexible
http://www.teradataforum.com/teradata/20020728_044326.htm

If you are familiar with installation of User Defined Functions - this library (download) may help http://downloads.teradata.com/download/extensibility/teradata-udfs-for-popular-oracle-functions - remember to install the replace function as oreplace because replace is a keyword
0
 
Mark WillsTopic AdvisorCommented:
G'Day, just passing through the Teradata Zone and saw this one still open...

Well, there is no simple way of doing it other than a series of substrings being concatenated together....

(case when substr(my_column,1,1) = '.' then '' else substr(my_column,1,1) end)
||
(case when substr(my_column,2,1) = '.' then '' else substr(my_column,2,1) end)
||
(case when substr(my_column,3,1) = '.' then '' else substr(my_column,3,1) end)
||
(case when substr(my_column,4,1) = '.' then '' else substr(my_column,4,1) end)
||
(case when substr(my_column,5,1) = '.' then '' else substr(my_column,5,1) end)
||
(keep going for how ever long the string is - need to do every character)

You could probably create the above type of construct as a function... otherwise check those links above - looks like they are talking about functions...
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
sabeeshCommented:
you could repeat the following function twice if the `.` occurs only twice in all the values.

substring(column FROM 1 FOR POSITION(`.` IN column) - 1) || substring(column FROM POSITION(`.` IN column) + 1)
0
 
Mark WillsTopic AdvisorCommented:
Well all 4 experts posted something to help answer the question, so split amongst all 4.
0
 
seenallCommented:
I agree with the previous poster - All 4 posts were valid, - and this post I suspect will be useful for some time to come until Teradata introduce a pre-compiled replace function
Please apply some point distribution
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The issue is that we do not know if the proposed solutions really hit what was intended to request. So either all or nothing to accept. All recommendations are valid, but most are completely oversized. Only sabeesh's solution is exactly fitting, because it consideres two dots only. On the other hand, "strip out all periods" could also mean there are more than two, and in that case sabeesh's solution does not fit at all. I really cannot determine which answers are really correct for this case, only the asker can, hence I recommended deletion.

Qlemo
Cleanup Volunteer
0
 
Mark WillsTopic AdvisorCommented:
Yep, completely understand the reasoning. And the comments have been posted to position accordingly.

But it is a good thread for Terradata "replace" in case anyone else needs it.

Sabeesh can have the "accepted" gong, the rest can be assists because they do provide good information.

Hard one to really score, but think there is value here.
0
 
seenallCommented:
without parroting - all comments are valid - Hopefully congratulations go to Sabeesh -

An interesting case that I shall certainly bookmark
0
 
South ModModeratorCommented:
All,
 
Following an 'Objection' by mark_wills (at http://www.experts-exchange.com/Q_26664006.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
SouthMod
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now