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

Help w/ stored proc creation - extract only numeric from alphanumeric

aj
DB2 WSE 8.1 FP 5
Red Hat Linux AS 2.1
(LUW)

I am looking to write a stored procedure
GETNUMBER(p_input VARCHAR(50)) RETURNS Integer
that will return to me only the numeric portion of
alphanumeric p_input, dropping the alpha portion(s).

So,
GETNUMBER('B999') would return 999
GETNUMBER('B888A') would return 888
GETNUMBER('ABCDEFG123') would return 123
GETNUMBER('12345YXEWQ') would return 12345

You get the idea.....

I have this written as a Java UDF, but have had nothing but
headaches w/ v8 FP5 Java VM FMP issues.

Can this be written as a stored procedure?

Any help appreciated.

aj

Nov 12 '05 #1
2 2631
Ian
aj wrote:
DB2 WSE 8.1 FP 5
Red Hat Linux AS 2.1
(LUW)

I am looking to write a stored procedure
GETNUMBER(p_input VARCHAR(50)) RETURNS Integer
that will return to me only the numeric portion of
alphanumeric p_input, dropping the alpha portion(s).

So,
GETNUMBER('B999') would return 999
GETNUMBER('B888A') would return 888
GETNUMBER('ABCDEFG123') would return 123
GETNUMBER('12345YXEWQ') would return 12345


TRANSLATE can help, although it's not so easy without character classes
(since you basically have to specify every character except for 0-9.

INT(TRANSLATE('B999','','AaBbCcDdEeFfGgHhIiJjKkLlM mNnOoPpQqRrSsTtUuVvWwXxYyZz'))
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Nov 12 '05 #2
Why do you want to implement as stored procedure?
It's easy to implement as SQL UDF.
For example:
CREATE FUNCTION GETNUMBER(p_input VARCHAR(50))
RETURNS Integer
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CAST(REPLACE(TRANSLATE(p_input, '', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
' ', '') AS INTEGER)
!
Nov 12 '05 #3

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

Similar topics

2
by: June Moore | last post by:
Hi all, I have a stored procedure that return a resultset e.g. stored proc: get_employee_details select emp_id, emp_name, emp_salary, emp_position from empoloyee I would like to write...
11
by: shan | last post by:
how to declare a variable that should contain both alpahabets and numbers.It should not be an string or char array.
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
3
by: comp_databases_ms-sqlserver | last post by:
This post is related to SQL server 2000 and SQL Server 2005 all editions. Many of my stored procedures create temporary tables in the code. I want to find a way to find the query plan for these...
4
by: raghav | last post by:
Hi all I am having a SP which is returning a value......Now I have to store that value in session...I saw some examples in msdn lib ----> string Name=string.Empty; Session=Name.ToString(); ...
3
by: satkins | last post by:
Hello everyone. I've been trying to find if this is even possible but nothing I've found has really helped. I've got a stored proc with a few input parameters and one output parameter. I would...
5
lotus18
by: lotus18 | last post by:
Hello World! I have a sample code here written in vb .net that restricts the textbox to accept only alpha, alphanumeric or numeric characters. Public Enum MyOption Alpha = 1 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.