Jony_Junior
Jony_Junior

Reputation: 35

Oracle numbers filtering

I have the following query:

SELECT distinct INCOME_LEVEL
FROM CUSTOMERS
where INCOME_LEVEL like '%-%'

Which returns:

Query output

I need to Leave only those levels that are in the format "999,999 - 999,999", where the number "9" means that any of the digits 0-9 are possible.

Upvotes: 0

Views: 34

Answers (2)

Littlefoot
Littlefoot

Reputation: 142733

Presuming that values in that column - that contain the - character - always look like 250,000 - 299,999 (i.e. have numbers, not letters or any other characters, while there's always one space between numbers), you could even try with

select distinct income_level
from customers
where income_level like '%-%'
  and length(income_level) = 17

Upvotes: 1

MT0
MT0

Reputation: 167981

You can use REGEXP_LIKE:

SELECT DISTINCT
       income_level
FROM   customers
WHERE  REGEXP_LIKE( income_level, '^\d{3},\d{3}\s*-\s*\d{3},\d{3}$' )

Upvotes: 1

Related Questions