Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL to idenfity gaps in ranges

kron777Jun 1 2012 — edited Jun 6 2012
A friday SQL teaser! 11.2.03.

I have a table with indicator and start, end ranges. I need an SQL to return ranges that are not excluded.
create table k_test (indicator varchar2(10),start_val number, end_val number);

insert into k_test values('INCLUDE',000,999);
insert into k_test values('EXCLUDE',000,503);
insert into k_test values('EXCLUDE',507,511);
insert into k_test values('EXCLUDE',514,999);
A select statement please to return the ranges that are "open", i.e. not excluded.
504
505
506
512
513
I can manage this in PL/SQL, keen to know a clever way in SQL.
This post has been answered by Peter vd Zwan on Jun 1 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2012
Added on Jun 1 2012
13 comments
369 views