0

I have got a table with a column that is type of VARCHAR2(255 BYTE). I would like to select only these rows that have numbers as a value, so I discard any other values as for example "lala","1z". I just want to have pure numbers from 1 to ..... 999999999 (just digital numbers in other words) :P

Could you tell me how to make it?

3
  • Hi maksi111, what sql plateform are you using? Commented Jan 13, 2020 at 14:25
  • @zip oracle sql developer Commented Jan 13, 2020 at 14:25
  • 2
    orafaq.com/wiki/IS_NUMBER Commented Jan 13, 2020 at 14:28

4 Answers 4

2

if you're using Oracle 12c r2 or later then use the built-in validate_conversion() function:

select *
from your_table
where validate_conversion(cast(your_column as number)) = 0

validate_conversion() returns 0 when the proposed conversion would succeed and 1 when it wouldn't. It also supports date and timestamp conversions. Find out more.

Sign up to request clarification or add additional context in comments.

Comments

1

Something like this is the usual option. You could use regexp, but it's usually a bit slower.

select column1 
from tableA
where translate(column1, '1234567890', '') is null;

1 Comment

it has worked with trim(TRANSLATE(..., '0123456789-,.', ' ')) is null;
1

Here's the regexp version kfinity referred to. The regex matches a line consisting of 1 or more digits.

select column1 
from tableA
where regexp_like(column1, '^\d+$');

Comments

1

You don't want zero to start a number. So it seems like regular expressions are the way to go:

where regexp_like(column1, '^[1-9][0-9]*$');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.