Page 1 of 1

convert char to integer

Posted: Sun Jun 11, 2006 10:20 pm
by rafidwh
Hi All,
I have a source flat file with one of the column srccol1 char3 and my corresponding column in the database is trgcol1 num3.

If you look at the above description the souce column datatype is char and the target column is number.
Should I need to convert the char to num to populate to table? or will Datastage internally converts the char to num?
If doesn't convert the how I need to convert?
Please suggest me
Thanks in advance

Regards,
Saik.

Re: convert char to integer

Posted: Sun Jun 11, 2006 11:48 pm
by balajisr
rafidwh wrote:Hi All,
I have a source flat file with one of the column srccol1 char3 and my corresponding column in the database is trgcol1 num3.

If you look at the above description the souce column datatype is char and the target column is number.
Should I need to convert the char to num to populate to table? or will Datastage internally converts the char to num?
If doesn't convert the how I need to convert?
Please suggest me
Thanks in advance

Regards,
Saik.
Datastage will not convert char to num. You need to convert char to num using Int() Function.

Posted: Mon Jun 12, 2006 12:19 am
by rafidwh
But from the help,I found that the int() function is returning the integer portion from the number value like srccol value is 2.3 ,if we use Int it returns as 2,
Now will Int() aslo converts char to integer

Posted: Mon Jun 12, 2006 1:01 am
by balajisr
rafidwh wrote:But from the help,I found that the int() function is returning the integer portion from the number value like srccol value is 2.3 ,if we use Int it returns as 2,
Now will Int() aslo converts char to integer
Indeed. Int() returns integer portion from the number value.

I think i got it totally wrong. For checking whether the string contains only numeric value do not use Alpha() function use Num() function which checks whether the string is numeric.

As for conversion i am not sure that Int() is the right method to use for converting char to integer. Sorry for my mistake.

Posted: Mon Jun 12, 2006 2:11 am
by ArndW
DataStage will perform an implicit conversion from a string to a number and vice-versa.

Code: Select all

   x = '123'
   x = x : '4'
   x = x * 2
   x = x[3,2]

Posted: Mon Jun 12, 2006 3:21 am
by rafidwh
Hi Arnd
so that means,I need not use any coding to convert char to integer
Is that you mean to say.

Thanks
Saik

Posted: Mon Jun 12, 2006 3:28 am
by ArndW
If your CHARacter field contains only digits then you do not need to perform any explicit conversions, see the example I gave in the previous post.
If your CHAR fields contains mixed numeric and text then you will need to provide some conversion code to make sure that DataStage interprets this field correctly. There are ICONV() conversions such as "MCN" that you can use to effect this.

Posted: Mon Jun 12, 2006 5:05 am
by rafidwh
what should be done if a character like (A,B,C) occurs,should these rows need to be rejected by using num() or any conversions are possible.

Posted: Mon Jun 12, 2006 5:10 am
by ArndW
Rafidwh - did you actually read my post? Please look into your BASIC programming PDF file and search for the MCN conversion and that will answer your question on what can technically be done with alphabetic characters in a numeric string. Nobody here can answer what needs to be done according to your business rules.

Posted: Fri Jul 14, 2006 12:14 pm
by NBALA
Hi All,

I have the similar question, I have data which is signed decimal value from source flat file. This field will have -/+ like ' -213.23004'. We need to keep the sign on the target (oracle number). How to do this using DS.
Note: We are using DS 7.5

Please some one help me.

Thanks in advance
-NB

Posted: Fri Jul 14, 2006 12:41 pm
by DSguru2B
Please start a new post.
Datastage will take it as a signed decimal. You dont need to worry about it. Negative decimal numbers are preserved.