473,388 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Finding if a character is alphanumeric

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

Nov 12 '05 #1
2 11667
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.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
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
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Astra | last post by:
Hi All I know an SQL Server timestamp seems to be as useful as rocking horse for show jumping, but I'm hoping you know a 'fudge' to get me round a problem or at least confirm that it isn't...
3
by: peterbe | last post by:
In a text that contains references to numbers like this: #583 I want to find them with a regular expression but I'm having problems with the hash. Hopefully this code explains where I'm stuck: ...
10
by: M Bourgon | last post by:
I'm trying to figure out how to find the last whitespace character in a varchar string. To complicate things, it's not just spaces that I'm looking for, but certain ascii characters (otherwise,...
3
by: Duy Lam | last post by:
I'm using collation SQL_Latin1_General_CP1_CI_AS and I need to sort a varchar field. There are some elements, however, that I want to come AFTER any alphabetic characters. Is there any character...
1
by: Hemanth | last post by:
Hello, How do I find the first and last non-numeric char positions (using regexp) in an alphanumeric string? For example, 99ABC1A => should return 2, 6 DE8A1 => should return 0, 3 Thanks,
1
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file,...
7
by: kanepart2 | last post by:
Hey all, I have to validate a textbox in windows forms for alphanumeric characters such that non alphanumeric key presses are ignored. Some help would be appreciated
2
by: Sarahger9 | last post by:
Hi, I am writing a code that requires me to search for words within a text document. I had to build up words one character at a time in order to ignore punctuation when I search for the words. I...
2
by: Vladimir Ghetau | last post by:
Hi guys, This is a weird problem, and I'm not sure if I got it right. Just a practical example, that will describe my problem: I'm connecting to google.com host on port 80 using fsock open,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.