473,383 Members | 1,788 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,383 software developers and data experts.

Searching SQL-Funktion ...

Hello,

we have a database with one column CHAR(10), which contains numeric data
(10 digits).
(That was not my idea).

Now, I have to find out all rows, which do not have numeric data in this
column.

Unfortunately, I don't know the corresponding function for the
followeing query:

select * from table where function(column)>999999999;

Any suggestions?

Thanks in advance for any support.

Dirk

Nov 12 '05 #1
8 8612
Dirk Deimeke wrote:
Hello,

we have a database with one column CHAR(10), which contains numeric data
(10 digits).
(That was not my idea).

Now, I have to find out all rows, which do not have numeric data in this
column.

Unfortunately, I don't know the corresponding function for the
followeing query:

select * from table where function(column)>999999999;

Any suggestions?


Besides the obvious use of regular expressions
(http://www.ibm.com/developerworks/db...301stolze.html)

you could do something like this:

SELECT *
FROM yourTable
WHERE SUBSTR(column, 1, 1) NOT BETWEEN '0' AND '9' AND
SUBSTR(column, 2, 1) NOT BETWEEN '0' AND '9' AND
...
SUBSTR(column, 10, 1) NOT BETWEEN '0' AND '9'

You can also wrap the predicates in the WHERE clause into a function if you
like. And if you want to generalize this to be able to deal with strings
of different lengths, have a look here for some ideas:
http://www.ibm.com/developerworks/db...301stolze.html

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
Knut Stolze:

Besides the obvious use of regular expressions (http://www.ibm.com/developerworks/db...301stolze.html)

That is pretty cool. Thank you for the link.
you could do something like this:
SELECT *
FROM yourTable
WHERE SUBSTR(column, 1, 1) NOT BETWEEN '0' AND '9' AND
SUBSTR(column, 2, 1) NOT BETWEEN '0' AND '9' AND
...
SUBSTR(column, 10, 1) NOT BETWEEN '0' AND '9'


I wanted to avoid that ...

It could help to react on the error message you get by using:
select * from ourTable where int(column)>0;

Thank you for your support.

Kind regards.

Dirk

Nov 12 '05 #3
Here is a sample UDF ISNUMERIC/ISNUM.

--
-- DB2 UDB UDF(User-Defined Function) Samples for Migration
--
-- Created: 2002/07/18
-- Updated: 2004/02/08
--
-- Name of UDF: ISNUMERIC (Source VARCHAR(40))
-- ISNUM (Source VARCHAR(40))
--
-- Used UDF: None
--
-- Description: Returns 1 when the input string is a valid integer or
decimal representation,
-- otherwise returns O.
--
-- Validity test cases.
-- Test 1 : All characters are '0123456789.-+' or
blank.
-- Test 2 : No other characters exists left of '-' or
'+' except blank(s).
-- Test 3-1: Number of '-' or '+' should be 0 or 1.
-- Test 3-2: Number of '.' should be 0 or 1.
-- Test 4 : No blanks are allowed between characters
except after leading '-' or '+'.
-- Test 5 : It should have at least one digit
character.
--
-- Author: TOKUNAGA, Takashi
--

CREATE FUNCTION ISNUMERIC (Source VARCHAR(40))
RETURNS INTEGER
LANGUAGE SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE
WHEN translate(source,'','0123456789.-+') <> ''
THEN 0
WHEN posstr(ltrim(source),'-') > 1
OR posstr(ltrim(source),'+') > 1
THEN 0
WHEN length(rtrim(ltrim(translate(source,'','0123456789 .')))) > 1
OR length(rtrim(ltrim(translate(source,'','0123456789-+')))) > 1
THEN 0
WHEN posstr(ltrim(rtrim(translate(source,'','-+'))),' ') > 0
THEN 0
WHEN translate(source,'','.-+') = ''
THEN 0
ELSE 1
END
!

--------------------------------------------------------------------------
CREATE FUNCTION ISNUM (Source VARCHAR(40))
RETURNS INTEGER
SOURCE ISNUMERIC
!
Nov 12 '05 #4
Tokunaga T.:
Here is a sample UDF ISNUMERIC/ISNUM.


Thanks a lot for your support.

Can you please explain me, how do i get this funktion into db2?

db2 -td! -vf yourfunction.sql

Is that the right way?

Kind regards

Dirk
Nov 12 '05 #5
> Can you please explain me, how do i get this funktion into db2?

db2 -td! -vf yourfunction.sql

I did not try this.
Usually, I copy and paste on Command Editor and execute it.
Nov 12 '05 #6
Tokunaga T.:
I did not try this.
Usually, I copy and paste on Command Editor and execute it.


That is too easy ;-)

Thanks again.

Dirk
Nov 12 '05 #7
Dirk Deimeke:
I did not try this.
Usually, I copy and paste on Command Editor and execute it.


Your function works great.

Thanks a lot.

Kind regards,

Dirk Deimeke

Nov 12 '05 #8
raid3n
2
Dirk Deimeke:
[color=blue][color=green]
>> I did not try this.
>> Usually, I copy and paste on Command Editor and execute it.[/color][/color]

Your function works great.

Thanks a lot.

Kind regards,

Dirk Deimeke
Hello,

I create this table in DB2 to experiment the function ISNUMERIC:

create table tab (
prova VARCHAR(40) CHECK (ISNUMERIC(prova) = 1)
);

but i have some errors: pratically the functions not exists

I copy the funcion in the editor and all is ok. But i can not use it.
Excuse my bad english

Regards
Andrea
Jul 5 '06 #9

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

Similar topics

4
by: donald | last post by:
Hi all, I have a website running asp (about to move to asp.net soon though) which has a list of DVD's I have the various pages I want, last 10, listing, full listing ect, but the one page i can't...
3
by: aaj | last post by:
This is a simple question compared to some of the stuff that gets asked (and answered) here, but sometimes its easy to over look the simpler things. I've been working with databases for a few...
0
by: Adam | last post by:
I am currently determining the architecture for a rewrite of an existing retailed software product - moving from Smalltalk to C# .Net. It is to be a rich-client single-user desktop application. The...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
3
by: ANDY AIYER | last post by:
Guru's! Your time and guidance is much appreciated in this task that i am trying to get done. Background I have a SQL Server 2000 database table which contains 2 Fields (RecordID, XMLData...
4
by: Jordan S. | last post by:
Using .NET 2.0 (C#) I'm writing a small app that will have a "Person" class that exposes FirstName and LastName properties. At runtime, a "People" collection will be populated with a few thousand...
5
by: justobservant | last post by:
When more than one keyword is typed into a search-query, most of the search-results displayed indicate specified keywords scattered throughout an entire website of content i.e., this is shown as...
8
by: Allan Ebdrup | last post by:
What would be the fastest way to search 18,000 strings of an average size of 10Kb, I can have all the strings in memory, should I simply do a instr on all of the strings? Or is there a faster way?...
3
by: danielleissy | last post by:
Firstly i would like to know the difference between Keyword searching using SQL and partial matching of a search. I have to search for a book by key word in the book title. But allow TWO key words...
3
by: Daniel Fetchinson | last post by:
Does Python 2.5.2's embedded SQLite support full text searching? Sqlite itself is not distributed with python. Only a python db api compliant wrapper is part of the python stdlib and as such it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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...

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.