| Read a string char by char and compare [message #638590] |
Mon, 15 June 2015 11:40  |
 |
apenkov
Messages: 20 Registered: October 2012
|
Junior Member |
|
|
Hello,
I have table1 with one column holding numbers like:
359876500911
359877500912
359878500913
359879500914
And table2 holding number prefixes like:
And I want to get all numbers starting with 359, but excluding these starting with the prefixes into table2, so at the end my result to be:
359878500913
359879500914
I am not so good with Oracle, so I have no idea if this is possible and how it can be done. I was trying something with EXISTS, but it doesn't work. Please, any help.
Thanks in advance!
Atanas
|
|
|
|
|
|
| Re: Read a string char by char and compare [message #638593 is a reply to message #638590] |
Mon, 15 June 2015 11:53   |
 |
Michel Cadot
Messages: 68776 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
OK, this is a homework, so show us what you already tried and where you are stuck.
Hint: LIKE and NOT LIKE should do the trick.
With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data.
[Updated on: Mon, 15 June 2015 11:54] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Read a string char by char and compare [message #638611 is a reply to message #638610] |
Mon, 15 June 2015 15:33   |
Solomon Yakobson
Messages: 3312 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Data magic:
SQL> insert into table1 values('777123456789');
1 row created.
SQL> select t1.a_number
2 from table1 t1 left outer join table2 t2
3 on t1.a_number like t2.prefixes||'%'
4 where t2.prefixes is null
5 /
A_NUMBER
----------------------------------------
359878500913
359879500914
777123456789
SQL> select t1.a_number
2 from table1 t1 left outer join table2 t2
3 on t1.a_number like t2.prefixes||'%'
4 where t2.prefixes is null
5 and a_number like '359%'
6 /
A_NUMBER
----------------------------------------
359878500913
359879500914
SQL> select *
2 from table1
3 where a_number like '359%'
4 and not exists(
5 select 1
6 from table2
7 where a_number like prefixes || '%'
8 )
9 /
A_NUMBER
----------------------------------------
359878500913
359879500914
SQL>
SY.
|
|
|
|
|
|
|
|