这是一种选择;第 1 - 8 行的示例数据。您可能感兴趣的查询从第 9 行开始。根据您使用的工具,'&&terms' 可能看起来与此不同(例如:terms)。这是 SQL*Plus。另外,我用缩写代替了你的“宿舍”之类的东西(不想打字那么多)。
SQL> with months (mon, num) as
2 (select 'jan', 1 from dual union all
3 select 'feb', 2 from dual union all
4 select 'mar', 3 from dual union all
5 select 'apr', 4 from dual union all
6 select 'may', 5 from dual union all
7 select 'jun', 6 from dual
8 )
9 select *
10 from months
11 where mon in
12 (select *
13 from table(sys.odcivarchar2list('jan', 'feb', 'mar'))
14 where '&&terms' = 'FQ'
15 union all
16 select *
17 from table(sys.odcivarchar2list('apr', 'may', 'jun'))
18 where '&&terms' = 'SQ'
19 union all
20 select *
21 from table(sys.odcivarchar2list('jan', 'feb', 'mar', 'apr', 'may', 'jun'))
22 where '&&terms' = 'FH'
23 )
24 order by num;
Enter value for terms: SQ
MON NUM
--- ----------
apr 4
may 5
jun 6
--
SQL> undefine terms
SQL> /
Enter value for terms: FH
MON NUM
--- ----------
jan 1
feb 2
mar 3
apr 4
may 5
jun 6
6 rows selected.
SQL>