create table MyTable(
keyCol char(1) primary key,
f1 number(2) not null,
f2 number(2) not null,
f3 number(2) not null,
f4 number(2) not null,
f5 number(2) not null,
f6 number(2) not null,
f7 number(2) not null,
f8 number(2) not null,
f9 number(2) not null,
f10 number(2) not null);
insert into MyTable values('A',0,0,0,0,0,0,0,0,0, 0);
insert into MyTable values('B',1,2,3,4,5,6,7,8,9,10);
insert into MyTable values('C',1,0,0,0,0,0,0,0,0, 0);
insert into MyTable values('D',0,2,0,0,0,0,0,0,0, 0);
insert into MyTable values('E',0,0,3,0,0,0,0,0,0, 0);
insert into MyTable values('F',0,0,0,4,0,0,0,0,0, 0);
insert into MyTable values('G',0,0,0,0,5,0,0,0,0, 0);
insert into MyTable values('H',0,0,0,0,0,6,0,0,0, 0);
insert into MyTable values('I',0,0,0,0,0,0,7,0,0, 0);
insert into MyTable values('J',0,0,0,0,0,0,0,8,0, 0);
insert into MyTable values('K',0,0,0,0,0,0,0,0,9, 0);
insert into MyTable values('L',0,0,0,0,0,0,0,0,0,10);
insert into MyTable values('M',1,0,0,0,0,0,0,0,0,10);
insert into MyTable values('N',0,0,3,0,5,0,0,0,0, 0);
commit;
col f1 for 99
col f2 for 99
col f3 for 99
col f4 for 99
col f5 for 99
col f6 for 99
col f7 for 99
col f8 for 99
col f9 for 99
col f10 for 99
--■■■decode関数を使う方法■■■
select keyCol,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10
from MyTable
where decode( f1,0,0,1)+decode(f2,0,0,1)+decode(f3,0,0,1)
+decode( f4,0,0,1)+decode(f5,0,0,1)+decode(f6,0,0,1)
+decode( f7,0,0,1)+decode(f8,0,0,1)+decode(f9,0,0,1)
+decode(f10,0,0,1) = 1;
--■■■in述語を使う方法■■■
select keyCol,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10
from MyTable
where (f1,f2,f3,f4,f5,f6,f7,f8,f9,f10) in
((f1, 0, 0, 0, 0, 0, 0, 0, 0, 0),
( 0,f2, 0, 0, 0, 0, 0, 0, 0, 0),
( 0, 0,f3, 0, 0, 0, 0, 0, 0, 0),
( 0, 0, 0,f4, 0, 0, 0, 0, 0, 0),
( 0, 0, 0, 0,f5, 0, 0, 0, 0, 0),
( 0, 0, 0, 0, 0,f6, 0, 0, 0, 0),
( 0, 0, 0, 0, 0, 0,f7, 0, 0, 0),
( 0, 0, 0, 0, 0, 0, 0,f8, 0, 0),
( 0, 0, 0, 0, 0, 0, 0, 0,f9, 0),
( 0, 0, 0, 0, 0, 0, 0, 0, 0,f10))
and (f1,f2,f3,f4,f5,f6,f7,f8,f9,f10) != ((0,0,0,0,0,0,0,0,0,0));