Unix Technical Forum

Newbie question..

This is a discussion on Newbie question.. within the DB2 forums, part of the Database Server Software category; --> Hi everyone, I was wondering if anyone can tell me how to convert a character string to numeric in ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 08:17 AM
Joe
 
Posts: n/a
Default Newbie question..

Hi everyone,

I was wondering if anyone can tell me how to convert a character string to numeric in DB2 version 8.2. I have tried the following, but, it won't work:

select INTEGER('1234567899') from a.table1

Also tried decimal function, but, no luck.

The column in the table is ten characters long.

Any help is very much appreciated.

-J.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 08:17 AM
Serge Rielau
 
Posts: n/a
Default Re: Newbie question..

Joe wrote:
> Hi everyone,
>
> I was wondering if anyone can tell me how to convert a character string
> to numeric in DB2 version 8.2. I have tried the following, but, it won't
> work:
>
> select INTEGER('1234567899') from a.table1

What didn't work, and how?
Here is what I get:
db2 => select INTEGER('1234567899') from sysibm.sysdummy1;

1
-----------
1234567899

1 record(s) selected.


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 08:17 AM
Joe
 
Posts: n/a
Default Re: Newbie question..

Database field type is varchar(10). Exmple:
select INTEGER(field1) from a.table1

I get the following error messasge:
Error: SQL0420N Invalid character found in a character string argument of
the function "INTEGER". SQLSTATE=22018

(State:22018, Native Code: FFFFFE5C)

0 Row(s) affected

SQL0420N Invalid character found in a character string argument of the
function "INTEGER". SQLSTATE=22018

-J.

"Serge Rielau" <srielau@ca.ibm.com> wrote in message
news:4eoe6pF1f26aoU1@individual.net...
> Joe wrote:
>> Hi everyone,
>> I was wondering if anyone can tell me how to convert a character string
>> to numeric in DB2 version 8.2. I have tried the following, but, it won't
>> work:
>> select INTEGER('1234567899') from a.table1

> What didn't work, and how?
> Here is what I get:
> db2 => select INTEGER('1234567899') from sysibm.sysdummy1;
>
> 1
> -----------
> 1234567899
>
> 1 record(s) selected.
>
>
> --
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab
>
> IOD Conference
> http://www.ibm.com/software/data/ond...ness/conf2006/



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 08:17 AM
Mark A
 
Posts: n/a
Default Re: Newbie question..

"Joe" <sirguicho@hotmail.com> wrote in message
news:e673ug$2cr$1@news1.ucsd.edu...
> Database field type is varchar(10). Exmple:
> select INTEGER(field1) from a.table1
>
> I get the following error messasge:
> Error: SQL0420N Invalid character found in a character string argument of
> the function "INTEGER". SQLSTATE=22018
>
> (State:22018, Native Code: FFFFFE5C)
>
> 0 Row(s) affected
>
> SQL0420N Invalid character found in a character string argument of the
> function "INTEGER". SQLSTATE=22018
>
> -J.
>

From the DB2 sample database:

select cast (empno as integer) from emp


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 08:17 AM
Joe
 
Posts: n/a
Default Re: Newbie question..

I get the same error message when using cast..

-J.

"Mark A" <nobody@nowhere.com> wrote in message
news:9ZydnQYWGYsChxrZnZ2dnUVZ_t2dnZ2d@comcast.com. ..
> "Joe" <sirguicho@hotmail.com> wrote in message
> news:e673ug$2cr$1@news1.ucsd.edu...
>> Database field type is varchar(10). Exmple:
>> select INTEGER(field1) from a.table1
>>
>> I get the following error messasge:
>> Error: SQL0420N Invalid character found in a character string argument of
>> the function "INTEGER". SQLSTATE=22018
>>
>> (State:22018, Native Code: FFFFFE5C)
>>
>> 0 Row(s) affected
>>
>> SQL0420N Invalid character found in a character string argument of the
>> function "INTEGER". SQLSTATE=22018
>>
>> -J.
>>

> From the DB2 sample database:
>
> select cast (empno as integer) from emp
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 08:17 AM
Serge Rielau
 
Posts: n/a
Default Re: Newbie question..

Joe wrote:
> I get the same error message when using cast..

Joe, one of your rows has a string in the column that is not a number.
How many rows do you have? You can either eyeball the problem or write a
query that finds non numerics. (E.g. using TRANSLATE to map 0-9 to empty
string and looking and see which one doesn't end up empty...

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-27-2008, 08:17 AM
Joe
 
Posts: n/a
Default Re: Newbie question..

Thanks much, Serge. I will give this a try - I think you are right...

-J.
"Serge Rielau" <srielau@ca.ibm.com> wrote in message
news:4eosjnF1fhiksU1@individual.net...
> Joe wrote:
>> I get the same error message when using cast..

> Joe, one of your rows has a string in the column that is not a number.
> How many rows do you have? You can either eyeball the problem or write a
> query that finds non numerics. (E.g. using TRANSLATE to map 0-9 to empty
> string and looking and see which one doesn't end up empty...
>
> Cheers
> Serge
>
>
> --
> Serge Rielau
> DB2 Solutions Development
> IBM Toronto Lab
>
> IOD Conference
> http://www.ibm.com/software/data/ond...ness/conf2006/



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:58 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com