0

I have a table per_all_people_f with 3000-4000 person numbers. A few non-numeric characters are also there in some cases. I want to pick the highest number present in this table. When I am using the below query :

select ( MAX ( DISTINCT person_number) ) from per_all_people_f
where REGEXP_LIKE(person_number  , '^[[:digit:]]+$')

I am not getting the maximum number. I am getting 98098 although much bigger numbers like -1503388 already exist in the system.
How can I change the above query to get the maximum "Number" in this column.

1
  • 1
    Unrelated, but: distinct doesn't really make sense together with max() Commented Oct 30, 2019 at 14:40

2 Answers 2

5

You need to convert to a number. Otherwise the max() is as a string:

select MAX(TO_NUMBER(person_number))
from per_all_people_f
where REGEXP_LIKE(person_number, '^[[:digit:]]+$')
Sign up to request clarification or add additional context in comments.

Comments

1

This is conversion issue. You can use below method for conversion:

using CAST:

select MAX(CAST(person_number as NUMBER))
from per_all_people_f
where REGEXP_LIKE(person_number, '^[[:digit:]]+$')

or using TO_NUMBER :

select 
max(TO_NUMBER(person_number))
from per_all_people_f
where 
REGEXP_LIKE(person_number, '^[[:digit:]]+$')

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.