Author |
Message
|
schroederms |
Posted: Mon Sep 19, 2005 11:05 am Post subject: How to validate if a value of a tag is numeric |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
Anyone out there know how to check to see if a value of a tag is a NUMBER ? I've looked through the documentation on functions and can not seem to find what I'm looking for.
Thanks,
Mike |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Sep 19, 2005 11:10 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I guess it depends on what you mean by "tag".
If you mean, the value of an XML element, then you could always model the data using MRM, and validate it that way. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
elvis_gn |
Posted: Mon Sep 19, 2005 7:39 pm Post subject: |
|
|
 Padawan
Joined: 08 Oct 2004 Posts: 1905 Location: Dubai
|
If the domain is XML and the mxsd defines the "tag value" to be number then it will be validated at the input, else when you try to get the value to store in a string and it throws an exception then you know its a number and can only be stored in a integer variable. |
|
Back to top |
|
 |
jsware |
Posted: Tue Sep 20, 2005 4:14 am Post subject: |
|
|
 Chevalier
Joined: 17 May 2001 Posts: 455
|
Another way is to translate all the digits into nothing, and if you've got anything left, it can't be a valid numeric.
This only works with positive integers however:
Code: |
IF LENGTH(TRANSLATE(TRIM(integerString), '0123456789', '')) = 0 THEN
-- String is a valid integer
ELSE
-- String contains something other than 0-9 digits.
END IF; |
_________________ Regards
John
The pain of low quaility far outlasts the joy of low price. |
|
Back to top |
|
 |
mgk |
Posted: Tue Sep 20, 2005 4:31 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
And in Message Broker V6 there is a DEFAULT clause on a CAST so that if the CAST fails, instead of an exception being thrown, the value in the DEFAULT clause is used instead.
Like:
Code: |
SET result = CAST( myString INTEGER DEFAULT NULL); |
or
Code: |
SET result = CAST( myString INTEGER DEFAULT -1); |
Then you can check result for -1 or NULL or any other value you placed in the DEFAULT clause. _________________ 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 |
|
 |
schroederms |
Posted: Tue Sep 20, 2005 5:38 am Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
thanks all.
Based on what I'm doing, it looks like mgk solution would work for me if I was on V6, but we are not there yet. So I'll try using a SUBSTRING thru the data of the field checking each byte. Not what I really wanted to do. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Sep 20, 2005 11:12 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Also, IS NUM _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
schroederms |
Posted: Tue Sep 20, 2005 3:05 pm Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
jefflowrey,
I see no IS NUM function in the help. Could you expand?
Thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Sep 20, 2005 3:59 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
http://publib.boulder.ibm.com/infocenter/wbihelp/index.jsp?topic=/com.ibm.etools.mft.doc/ak01040_.htm wrote: |
Operator IS
The operator IS allows you to test whether a value is NULL.
This includes testing values INF, +INF, -INF, NAN (not a number), and NUM in any mixture of case. The alternative forms +INFINITY, -INFINITY, and NUMBER are also accepted.
If applied to non-numeric types, the result is FALSE.
The comparison operator (=) does not allow this because the result of comparing with NULL is NULL. It also allows you to use a more natural English syntax when testing boolean values.
Syntax diagram format: Railroad diagram Dotted decimal
Read syntax diagramSkip visual syntax diagram
IS operator
.-TRUE----.
>>-Operand--IS--+-----+--+-FALSE---+---------------------------><
'-NOT-' +-UNKNOWN-+
'-NULL----'
The result is TRUE if the value of the left operand is equal (or not equal if the NOT clause is present) to the specified value (TRUE, FALSE, UNKNOWN, or NULL). Otherwise the result is FALSE. |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mgk |
Posted: Wed Sep 21, 2005 1:36 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
I know the docs could be improved in this area, but, IS NUM (or IS NUMBER) does not allow you to check if a character string represents a number. It will always return FALSE if given a none numeric datatype
(that is anything other that FLOAT, DECIMAL INTEGER). For FLOAT and INTEGER it will always return TRUE because they are by definiton numeric (unless they are null in which case it will return FALSE)
It is really only useful when used with a DECIMAL, where it is designed to check that a DECIMAL numer is valid, which means that it checks that it is not NAN or INFINITY or NULL in one operation.
Regards, _________________ 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 |
|
 |
jefflowrey |
Posted: Wed Sep 21, 2005 3:41 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I thought, without checking it, that this might be a case where an implicit cast was done.
 _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mgk |
Posted: Wed Sep 21, 2005 3:55 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
There is an implicit cast done here, but only from CHARACTER to BOOL, which is only really useful if you are testing for IS TRUE or IS FALSE.
Regards, _________________ 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 |
|
 |
schroederms |
Posted: Wed Sep 21, 2005 4:40 am Post subject: |
|
|
 Disciple
Joined: 21 Jul 2003 Posts: 169 Location: IA
|
mgk,
Any change of
SET result = CAST( myString INTEGER DEFAULT NULL);
or
Code:
SET result = CAST( myString INTEGER DEFAULT -1);
Getting into version 5 FixPack 7?
Thanks,
Mike |
|
Back to top |
|
 |
|