How to separate charcters and integers?

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

nareshketepalli
Participant
Posts: 36
Joined: Mon Jun 28, 2010 11:24 pm
Location: seepz

How to separate charcters and integers?

Post by nareshketepalli »

Hi,
How to separate the charcters and integers?
Source has the one column ,the datatype is varchar and target has to be two columns.
Ex:

Source -----------------> Target
Column -----------------> Char_col --- Num_col
A1b2c3 -----------------> abc --- 123

Is there any pre-defind fuction?

Thanks in advance..
NARESHKUMAR
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Use a BASIC Transformer stage (or a server job).

Code: Select all

Char_col  <==  Oconv(InLink.TheString,"MCA")
Num_col  <==  Oconv(InLink.TheString,"MCN")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Post by soumya5891 »

What is the length of the VARCHAR field? And are you using Datastage 8.5?
Soumya
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

How about in a Parallel job using an inverse pair of Convert() functions--one for each output column?
Choose a job you love, and you will never have to work a day in your life. - Confucius
nareshketepalli
Participant
Posts: 36
Joined: Mon Jun 28, 2010 11:24 pm
Location: seepz

Post by nareshketepalli »

I am using 8.1 and the length is 50.
NARESHKUMAR
prajesh
Participant
Posts: 7
Joined: Sun Apr 24, 2011 4:52 am

Post by prajesh »

Hi,

use substring function in transformer to get this output for current requirement.

seq----->txr----->seq2


in transformer u will craete two columns Char_col and Num_col

use substring fun in derivation of corresponding column

inlink.column(1,1):inlink.column(3,1):inlink.column(5,1)-->Char_col
inlink.column(2,1):inlink.column(4,1):inlink.column(6,1)-->num_col


regards,
rajesh.
prajesh
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I doubt that they always occur in the same spot each time, hence the question on how to detect them.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

qt_ky wrote:How about in a Parallel job using an inverse pair of Convert() functions--one for each output column?
Sure seems like that would work! :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Post by soumya5891 »

If the column length is greater then 6 ,say 8 then it will not work.According to nareshketepald the length of the field is 50.
Soumya
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

soumya5891 wrote:If the column length is greater then 6 ,say 8 then it will not work.
Please provide proof of that assertion. I don't believe it is correct.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What "it" won't work? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
nirav.parikh
Participant
Posts: 14
Joined: Thu Dec 13, 2007 2:57 am

Post by nirav.parikh »

For those who have similar requirement and the source oracle you can use some thing like the sql stated below:


select replace(translate('abc123pqr456','0123456789','~'),'~','') from dual;

select replace(translate('abc123pqr456','abcdefghijklmnopqrstuvwxyz','~'),'~','') from dual;

just an example you can tweak is as per your requirement.

Let me know if it works for you.

Regards,
Nirav
Thanks & Regards
Nirav
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Using Convert() still seems like the simplest option...

Have you tried it?
Choose a job you love, and you will never have to work a day in your life. - Confucius
nirav.parikh
Participant
Posts: 14
Joined: Thu Dec 13, 2007 2:57 am

Post by nirav.parikh »

That Convert() option should work very well too. Just posted an alternative if someone wants to do that in the sql query itself. :D
Thanks & Regards
Nirav
jdsmith575210
Participant
Posts: 14
Joined: Mon Jan 19, 2009 9:06 pm

Post by jdsmith575210 »

If you're using Oracle and want to use SQL, I would consider regexp_replace.

Code: Select all

 SELECT regexp_replace(my_text, '\D', ''),
  regexp_replace(my_text, '\d', '')
   FROM
  ( SELECT 'Th4is298 is a 12 test' AS my_text FROM dual
  )

REGEXP_REPLACE(MY_TEXT,'\D','') REGEXP_REPLACE(MY_TEXT,'\D','') 
------------------------------- ------------------------------- 
429812                          This is a  test 
Post Reply