|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
How to identify the strting is numeric or not? |
« View previous topic :: View next topic » |
Author |
Message
|
javaforvivek |
Posted: Tue Jul 20, 2004 5:27 am Post subject: How to identify the strting is numeric or not? |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Hi I am developing an ESQL module, in which I need to know whether a variable (charatcer datatype) can be casted to a number or not..
what should I do? Has anybody used NaN for this? How to use it?
For e.g,
DECLARE string1 CHARACTER '1234';
DECLARE string2 CHARACTER 'abcd';
Use of CAST (string2 AS DECIMAL) gives me an error.
How to determine by ESQL, that string1 can be casted to number but string2 cannot?? _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
RocknRambo |
Posted: Tue Jul 20, 2004 7:15 am Post subject: |
|
|
Partisan
Joined: 24 Sep 2003 Posts: 355
|
you can scan through the string charecter by charecter to find out whether it is a numeric or not.
try this esql code .. (declaration not completed)
SET CHEK_STRING = TRUE;
WHILE(I <= LENGTH(STRING_NUM_OR_NOT)) DO
SET FIRST_CHAR = SUBSTRING(STRING_NUM_OR_NOT FROM I FOR 1);
IF(FIRST_CHAR < '0' OR FIRST_CHAR > '9') THEN
SET CHEK_STRING = FALSE;
END IF;
SET I = I+1;
END WHILE;
good luck.
-sanu |
|
Back to top |
|
 |
javaforvivek |
Posted: Tue Jul 20, 2004 7:35 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Thanks Sanu,
I had thought of this solution at first. But it is a bit cumbersome..
I had read about NAN in ESQL-Help.. Do anybody here know whether NAN can be used here or not? If yes, then how? _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
Lisa |
Posted: Tue Jul 20, 2004 7:49 am Post subject: NAN |
|
|
Master
Joined: 07 Jun 2002 Posts: 287 Location: NJ
|
Do you mean MQRO_NAN? These is part of the MQMD header.
Lisa |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jul 20, 2004 7:53 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
NAN can only be used with numeric data types, not with string data types.
At least, if I understand this properly
Quote: |
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. |
So, if you try to use NAN against a string, it will always be false. I think.
Unless an implicit cast occurs. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
javaforvivek |
Posted: Tue Jul 20, 2004 8:20 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Jeff,
what you said is correct, and that's why I have to follow the code that Sanu has provided...
Lisa,
sorry, but my question is not about message header parts.. _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|