ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Is Numeric in ESQL

Post new topic  Reply to topic
 Is Numeric in ESQL « View previous topic :: View next topic » 
Author Message
rossired
PostPosted: Wed Sep 06, 2006 9:31 am    Post subject: Is Numeric in ESQL Reply with quote

Novice

Joined: 22 Feb 2006
Posts: 22

Hi,

Whats the easiest way to check if a field has numeric data in it. I have a char field, that is supposed to contain numeric data, being mapped to a numeric field. I just want to check, so if its non numeric trash, I will just assign a zero.

Thanks
Vale
Back to top
View user's profile Send private message
rossired
PostPosted: Wed Sep 06, 2006 9:49 am    Post subject: Re: Is Numeric in ESQL Reply with quote

Novice

Joined: 22 Feb 2006
Posts: 22

rossired wrote:
Hi,

Whats the easiest way to check if a field has numeric data in it. I have a char field, that is supposed to contain numeric data, being mapped to a numeric field. I just want to check, so if its non numeric trash, I will just assign a zero.

Thanks
Vale


Ah, I think I may have found the answer: "IS NUMBER"
Back to top
View user's profile Send private message
mgk
PostPosted: Wed Sep 06, 2006 2:01 pm    Post subject: Reply with quote

Padawan

Joined: 31 Jul 2003
Posts: 1642

Hi,

IS NUMBER does not do what you think it does. It only checks a DECIMAL field or variable to ensure that the value in it is not NAN or INFINITY or NULL. It does not allow you to test a char field to see if it contains a valid numeric value.

That said, the way to do this on V6 of MB is to use a CAST with a DEFAULT clause which causes the CAST to substitute the value of the DEFAULT if the CAST would fail. In your case, you would have a DEFAULT clause of 0 to assign 0 if the cast fails.
_________________
MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions.
Back to top
View user's profile Send private message
m.schneider
PostPosted: Tue Jul 01, 2008 5:30 am    Post subject: Reply with quote

Centurion

Joined: 10 Apr 2007
Posts: 132
Location: Germany

Hi,

whats wrong with this code?

CREATE FUNCTION isNumeric(IN aValue CHARACTER)
RETURNS BOOLEAN
BEGIN

IF (CAST(aValue as DECIMAL DEFAULT 0)) = 0 THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;

END;

When I try to deploy this I receive the error. Illegal result type for expression. Valid types ar 'DECIMAL'.

Or do I need to set CCSID, etc. for a 0?
http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=/com.ibm.etools.mft.doc/ak05610_.htm
Back to top
View user's profile Send private message
m.schneider
PostPosted: Thu Jul 03, 2008 10:33 pm    Post subject: Reply with quote

Centurion

Joined: 10 Apr 2007
Posts: 132
Location: Germany

Any updates? I really need to solve this one.

Thx
Back to top
View user's profile Send private message
bielesibub
PostPosted: Fri Jul 04, 2008 12:37 am    Post subject: Reply with quote

Apprentice

Joined: 02 Jul 2008
Posts: 40
Location: Hampshire, UK

Hi there,

You could use:

IF LENGTH(TRANSLATE(aValue, '0123456789', '')) <> 0 THEN
RETURN FALSE
ELSE
RETURN TRUE
END IF;

This will replace any numeric values with a '', so hopefully the end result will be a string length of 0, anything else and you've got a non numeric character in your string. You could add a '.' and/or ',' in the searchString expression ('0123456789,.) to cater for decimal points etc..
Back to top
View user's profile Send private message MSN Messenger
m.schneider
PostPosted: Fri Jul 04, 2008 3:50 am    Post subject: Reply with quote

Centurion

Joined: 10 Apr 2007
Posts: 132
Location: Germany

Thanks, that's a pretty good workaround.
Back to top
View user's profile Send private message
m.schneider
PostPosted: Mon Jul 07, 2008 11:30 pm    Post subject: Reply with quote

Centurion

Joined: 10 Apr 2007
Posts: 132
Location: Germany

I'm still wondering how to use CAST with DEFAULT?
Back to top
View user's profile Send private message
paintpot
PostPosted: Fri Jul 11, 2008 9:24 am    Post subject: Reply with quote

Centurion

Joined: 19 Sep 2005
Posts: 112
Location: UK

Hi,
Works for Integer...I don't know if that will help with your particular data to test on. Decimal doesn't work for me (latest WMB 6.0, not WMB 6.1).

DECLARE aValue CHARACTER '1x34';

DECLARE nValue INTEGER;

SET nValue = CAST(aValue AS INTEGER DEFAULT 0);

-- it's a number (or zero)
IF (nValue > 0) THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
Back to top
View user's profile Send private message
DaveCanto
PostPosted: Fri Sep 10, 2010 5:29 am    Post subject: Reply with quote

Novice

Joined: 01 Feb 2008
Posts: 11
Location: Belgium - EU

m.schneider wrote:
Hi,

whats wrong with this code?

CREATE FUNCTION isNumeric(IN aValue CHARACTER)
RETURNS BOOLEAN
BEGIN

IF (CAST(aValue as DECIMAL DEFAULT 0)) = 0 THEN
RETURN FALSE;
ELSE
RETURN TRUE;
END IF;

END;

When I try to deploy this I receive the error. Illegal result type for expression. Valid types ar 'DECIMAL'.

Or do I need to set CCSID, etc. for a 0?
http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/index.jsp?topic=/com.ibm.etools.mft.doc/ak05610_.htm


According to IBM Help:

Code:
The DEFAULT parameter provides a method of avoiding exceptions being thrown from CAST statements by providing a last-resort value to return.

The DEFAULT parameter must be a valid ESQL expression that returns the same data type as that specified on the DataType parameter, otherwise an exception is thrown.


Because you're casting to a decimal value instead of an integer value, you shouldn't use 0 but try something like 0,0 or 0.0
_________________
Do not underestimate the power of ... unit testing and continuous integration.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Is Numeric in ESQL
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.