Skip to content
Advertisement

How to get partial string in oracle

I need to find all the users in the table that have this pattern

0123456789@gmail.com
0234567980@outlook.com
0234566666@live.gov

I only know the first 10 digits, the email address can be different.

I did something like this, but I get nothing back

   select * 
   from table where
        substr(user_identifier, 1,10) in (
        '0123456789','0234567980', '0234566666');

Is there another way that I can capture this data in oracle?

Thank you!

Advertisement

Answer

More a comment that a real answer, but with your sample data your code works well:

SQL> with someTable(user_identifier) as
  2  (
  3      select '0123456789@gmail.com' from dual union all
  4      select '0234567980@outlook.com' from dual union all
  5      select '0234566666@live.gov' from dual union all
  6      select '02345__XX__66666@live.gov' from dual
  7  )
  8  select *
  9  from someTable where
 10      substr(user_identifier, 1,10) in ('0123456789','0234567980', '0234566666');

USER_IDENTIFIER
----------------------
0123456789@gmail.com
0234567980@outlook.com
0234566666@live.gov

3 rows selected.

Say you have a table like this:

create table someTable(user_identifier ) as 
    select '0123456789@gmail.com' from dual union all
    select '0234567980@outlook.com' from dual union all
    select '0234566666@live.gov' from dual union all
    select '02345__XX__66666@live.gov' from dual

SQL> select * from someTable;

USER_IDENTIFIER
-------------------------
0123456789@gmail.com
0234567980@outlook.com
0234566666@live.gov
02345__XX__66666@live.gov

4 rows selected.

Your query would give

USER_IDENTIFIER
-------------------------
0123456789@gmail.com
0234567980@outlook.com
0234566666@live.gov

3 rows selected.

What do you need instead?

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement