×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

check for numeric value in varchar2 field & number validation

check for numeric value in varchar2 field & number validation

check for numeric value in varchar2 field & number validation

(OP)
Hi,
I have varchar2 field in a table which has data in number/alpha numeric field.
I want to extract records which has only numeric field with validation like the number should be between 1 & 10.

The sample data is given below.
A12
7
bb
5
4
c45
11

So out of the above 7 records, I need a query which display data 7,5,4 only bcoz the I need numbers between 1 & 10 only.
I tried translate(t.trn_matl_cd,'_0123456789','_') but it works for 1st step i.e. display all number fields but how do I do the validation to get number between 1 & 10.

Thanks & regards,
RAJ

RE: check for numeric value in varchar2 field & number validation

How about:

Select FieldA
From MyTable
Where FieldA Between 1 And 10


ponder


---- Andy

There is a great need for a sarcasm font.

RE: check for numeric value in varchar2 field & number validation

CREATE TABLE TEST
(COL1 VARCHAR2(20 BYTE));

SELECT * FROM TEST;

COL1
--------------------
A12
7
bb
5
4
C45
11

7 rows selected.

SELECT COL1
FROM TEST
WHERE REGEXP_LIKE(COL1,'^(?:1|2|3|4|5|6|7|8|9|10){1,2}$');



COL1
--------------------
7
5
4

SQL>

Bill
Lead Application Developer
New York State, USA

RE: check for numeric value in varchar2 field & number validation

(OP)
Thanks Andy & Bill.
@Bill - your query did work but when I added 1 in the data, it didn't show display after executing the query.

So I used the below SQL & it did display 1.
SELECT COL1
FROM TEST where
REGEXP_LIKE(COL1,'^(?:0|1|2|3|4|5|6|7|8|9|10)$')

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close