Solved

Teradata String Replace Function

Posted on 2010-08-27
12
9,443 Views
Last Modified: 2013-11-11
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
Comment
Question by:infa008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 40

Assisted Solution

by:Richard Quadling
Richard Quadling earned 125 total points
ID: 33545855
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
 
LVL 3

Assisted Solution

by:seenall
seenall earned 125 total points
ID: 33548710
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
 
LVL 51

Assisted Solution

by:Mark Wills
Mark Wills earned 125 total points
ID: 34023460
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Accepted Solution

by:
sabeesh earned 125 total points
ID: 34045762
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
 
LVL 51

Expert Comment

by:Mark Wills
ID: 34295936
Well all 4 experts posted something to help answer the question, so split amongst all 4.
0
 
LVL 3

Expert Comment

by:seenall
ID: 34296023
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 34296087
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
 
LVL 51

Expert Comment

by:Mark Wills
ID: 34296144
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
 
LVL 3

Expert Comment

by:seenall
ID: 34296216
without parroting - all comments are valid - Hopefully congratulations go to Sabeesh -

An interesting case that I shall certainly bookmark
0
 

Expert Comment

by:South Mod
ID: 34332928
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

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question