Find Strings in a String Field

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
swapnilverma
Participant
Posts: 135
Joined: Tue Aug 14, 2007 4:27 am
Location: Mumbai

Find Strings in a String Field

Post by swapnilverma »

How can I find multiple strings in a String column.

in sql we can use --

select xyz from abc
where UPPER(DESC) like '%MANGO%ORANGE%'


Read some of the old post here and found that I can use index function to find a string in string field.

Is there any specific function available to search multiple strings ?


In the mean time i can use index function twice to achive my logic..

but what if i have more strings to be searched in one field. More if else ??
Thanks
Swapnil

"Whenever you find whole world against you just turn around and Lead the world"
jseclen
Participant
Posts: 133
Joined: Wed Mar 05, 2003 4:19 pm
Location: Lima - Peru. Sudamerica
Contact:

Re: Find Strings in a String Field

Post by jseclen »

Hi swapnilverma,

The index function returns the position of a substring within a string, for your case:

this select:

select xyz from abc
WHERE UPPER (DESC) like '% MANGO% ORANGE%'

you can use the function as follows:

Index (UPPER (DESC) 'MANGO', 1) > 0 and Index (UPPER (DESC) 'ORANGE', 1) > 0

and return the records that matches both substrings
Saludos,

Miguel Seclén
Lima - Peru
swapnilverma
Participant
Posts: 135
Joined: Tue Aug 14, 2007 4:27 am
Location: Mumbai

Post by swapnilverma »

Thanks Saludos,

But I would still like to know if we have any function available to search multiple strings in one string column ...
Thanks
Swapnil

"Whenever you find whole world against you just turn around and Lead the world"
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The only thing I can think of that would do that is matches but the problem is I don't believe it is a valid PX function. You'd have to use a BASIC Transformer or a Server Shared Container to bring that functionality into your job from what I recall.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There's nothing out of the box in the parallel Transformer stage for searching for multiple string. Matches (in a BASIC Transformer stage) would do it. Or you could write your own parallel routine. A probably slower option would be an External Filter stage, that could use regular expressions to report a match/non-match result.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Information Analyzer (8.1.2 or later) has a matches_regex data rule available. It would be interesting to inspect the osh script that is generated from a data rule job that uses this, to see which operator is invoked. Alas, I'm not currently in a position to do that.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
battaliou
Participant
Posts: 155
Joined: Mon Feb 24, 2003 7:28 am
Location: London
Contact:

Post by battaliou »

Use the dcount function to establish how many occurances there are of your substring e.g. dcount(''dog cat dog cow dog'',"cat") will return 2
3NF: Every non-key attribute must provide a fact about the key, the whole key, and nothing but the key. So help me Codd.
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

That's not quite right---there's only one cat.

DCount counts the number of delimited fields in the first argument based on the delimiter specified in the second argument. There are two fields defined by the delimiter "cat".

I believe the easiest options to implement are the two Index() example given earlier or the Matches function in a BASIC transformer.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You can always do it in unix without much stretching. Yes? no? maybe so?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Oooo ooo! [thrusts hand into the air] Pick me! Pick me!

awk?
-craig

"You can never have too many knives" -- Logan Nine Fingers
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Somehow, I almost always overlook awk when thinking of a parallel job ;)
- james wiles


All generalizations are false, including this one - Mark Twain.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

AWK yes, i was thinking more like a simple grep :)
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

D'oh! [hangs head in shame]
-craig

"You can never have too many knives" -- Logan Nine Fingers
swapnilverma
Participant
Posts: 135
Joined: Tue Aug 14, 2007 4:27 am
Location: Mumbai

Post by swapnilverma »

thx guys ...

i have used index function multiple times for now ...

I just came to that this requirement is for "quick fix " and not for the long run ...

thanks again!
Thanks
Swapnil

"Whenever you find whole world against you just turn around and Lead the world"
Post Reply