|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Test Data Type in ESQL? |
« View previous topic :: View next topic » |
Author |
Message
|
NiceGuy |
Posted: Thu Sep 16, 2010 9:55 am Post subject: Test Data Type in ESQL? |
|
|
Apprentice
Joined: 11 Jun 2009 Posts: 37
|
Hi community,
I have a quick question:
Does anybody know if (or simply a way) to test if a passed CHARACTER can be CAST to a INTEGER?
Allow me to provide a watered down example:
Code: |
DECLARE nInt INTEGER;
DECLARE cString CHARACTER 'Net30';
DECLARE cNumber CHARACTER '30';
-- First Example
SET nInt = CAST(cString AS INTEGER); -- Fails/Exception
-- Second Example
SET nInt = CAST(cNumber AS INTEGER) -- Okay
|
The idea is I am not certain what the passed variable will hold prior
to casting.
Thanks again for your time. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 16, 2010 10:02 am Post subject: Re: Test Data Type in ESQL? |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
NiceGuy wrote: |
Does anybody know if (or simply a way) to test if a passed CHARACTER can be CAST to a INTEGER? |
- CAST with an impossible DEFAULT and test for the default
- CAST with a reasonable DEFAULT and continue processing
- TRANSLATE all the non-numerics out and see if it still has LENGTH
- TRANSLATE all the non-numerics out and CAST it with a DEFAULT
Other, possibly better methods are undoubtably possible. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
NiceGuy |
Posted: Thu Sep 16, 2010 12:52 pm Post subject: |
|
|
Apprentice
Joined: 11 Jun 2009 Posts: 37
|
Hi Thanks for the reply,
Vitor writes ...
Quote: |
TRANSLATE all the non-numerics out and see if it still has LENGTH
|
I had a feeling that suggestion may come up.
If I were to take this approach, is there an easy way to do this? What I
mean is if I were to use the TRANSLATE function, is there a quick and
easy way to supply all non-numeric characters?
For example:
Code: |
SET test = TRANSLATE(aVariable, 'a-zA-Z', '');
|
I realize this will not work, but provided as a means to help explain
myself.
Thank-you immensely for you time. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Sep 16, 2010 1:02 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
NiceGuy wrote: |
If I were to take this approach, is there an easy way to do this? What I
mean is if I were to use the TRANSLATE function, is there a quick and
easy way to supply all non-numeric characters?
For example:
Code: |
SET test = TRANSLATE(aVariable, 'a-zA-Z', '');
|
I realize this will not work, but provided as a means to help explain
myself. |
What about something like this:
Code: |
CREATE FUNCTION fOnlyNumbers(IN source CHARACTER) RETURNS CHARACTER
BEGIN
DECLARE cTemp CHARACTER
SET cTemp=TRANSLATE(source,'0123456789','');
RETURN TRANSLATE(source,cTemp,'');
END;
|
Less typing. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
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
|
|
|
|