select (case when 条件1 then 执行 when 条件2 then 执行2 else 执行其他 end) from 表
select 1 from a where 条件1 union all select 1 from b where !(条件1) and 条件2 union all select 1 from c where !(条件1) and !(条件2) and 条件3
使用动态SQL:select 1 from || ' table_name '; 不行吗?
select 1 from a where 条件1 union all select 1 from b where 条件2 union all select 3 from c where 条件3
SQL> ed 已写入 file afiedt.buf 1 select decode(&express,'1=1',(select count(1) from dual where 1=1), 2* '2<>3',(select count(1) from dual where 2<>3)) from dual SQL> / 输入 express 的值: '1=1' 原值 1: select decode(&express,'1=1',(select count(1) from dual where 1=1), 新值 1: select decode('1=1','1=1',(select count(1) from dual where 1=1),DECODE('1=1','1=1',(SELECTCOUNT(1)FROMDUALWHERE1=1),'2<>3',(SELECTCOUNT(1)FROMDU -------------------------------------------------------------------------------- 1
select 1 from a where 条件1 union all select 2 from b where 条件2 union all select 3 from c where 条件3
union all
select 1 from b where !(条件1) and 条件2
union all
select 1 from c where !(条件1) and !(条件2) and 条件3
where 条件1
union all
select 1 from b
where 条件2
union all
select 3 from c
where 条件3
SQL> ed
已写入 file afiedt.buf 1 select decode(&express,'1=1',(select count(1) from dual where 1=1),
2* '2<>3',(select count(1) from dual where 2<>3)) from dual
SQL> /
输入 express 的值: '1=1'
原值 1: select decode(&express,'1=1',(select count(1) from dual where 1=1),
新值 1: select decode('1=1','1=1',(select count(1) from dual where 1=1),DECODE('1=1','1=1',(SELECTCOUNT(1)FROMDUALWHERE1=1),'2<>3',(SELECTCOUNT(1)FROMDU
--------------------------------------------------------------------------------
1
where 条件1
union all
select 2 from b
where 条件2
union all
select 3 from c
where 条件3
2、如果条件1和条件2可以放在select中的where子句中,使用一个sql是可以的。