Serge Rielau wrote:
ma****@gmail.com wrote: Hi,
I am using db2 8.2 on Win XP
Can someone tell me , how do I find out that a given character is an
alphanumeric or a special character.
Does DB2 provide some built in function to know this?
Thanks in advance
mailar
Seems like a trivial function to write in either SQL or C.
CREATE FUNCTION isalphanumeric(c VARCHAR(1)) RETURNS INTEGER
NO EXTERNAL ACTIION DETERMINISTIC CONTAINS SQL
RETURN CASE WHEN UPPER(c) BETWEEN 'A' AND 'Z' OR c BETWEEN '0' and '9'
THEN 1 ELSE 0 END;
May needs an "OR c IN (....)" for some special characters
depending on language.
Alternatively, you could resort to an external function, written in C/C++ or
Java, and use the facilities of the programming language like "isalnum".
It should be something like this in C:
----------------------------------
#include <ctype.h>
#include <sqludf.h>
void isAlphaNum(
SQLUDF_VARCHAR *character,
SQLUDF_INTEGER *res,
SQLUDF_NULLIND *character_ind,
SQLUDF_NULLIND *res_ind,
SQLUDF_TRAIL_ARGS)
{
if (SQLUDF_NULL(character_ind)) {
*res_ind = -1;
}
else {
*res_ind = 0;
*res = isalnum(*character);
}
}
------------------------------
CREATE FUNCTION isAlphaNumeric(character VARCHAR(1))
RETURNS INTEGER
EXTERNAL NAME 'lib!isAlphaNum'
LANGUAGE C
PARAMETER STYLE SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURNS NULL ON NULL INPUT
NO SQL
ALLOW PARALLEL@
--
Knut Stolze
Information Integration
IBM Germany / University of Jena