Selection of numbers starting with 0, followed by [1-9]

Hello

I use 9i (it is a 3rd party software, I have no influcene on when they decide to upgrade...) under Unix.

In a table I would select all rows whose column x entries that

-start with 0
-have a number between 1-9 after the 0

So he should select rows with this value:

012345
098765
034343
044544

But it should not pick rows with values like this:

000343333
00-334-2323
22-333-333
AA - 00 - 000000

etc.

Can you please give me some tip?

Edited by: user590072 the 26.01.2010 00:46

You should make a habit of posting the CREATE TABLE statement so that we can play with your condition.
Does this work for you:

SQL> create table t as (
  2  select '0012345' col from dual union all
  3  select '012345' from dual union all
  4  select '098765' from dual union all
  5  select '034343' from dual union all
  6  select '044544' from dual union all
  7  select '000343333' from dual union all
  8  select '00-334-2323' from dual union all
  9  select '22---333--333' from dual union all
 10  select 'AA--00--000000' from dual
 11  );

Table created.

SQL> select *
  2  from   t
  3  where  substr(col, 1, 1) = '0'
  4  and    translate(substr(col,2),'x123456789','x') is null;

COL
--------------
012345
098765
034343
044544

4 rows selected.

Tags: Database

Similar Questions

Maybe you are looking for