当前位置: 代码迷 >> Oracle管理 >> 怎么根据某一变量,执行不同的select语句
  详细解决方案

怎么根据某一变量,执行不同的select语句

热度:356   发布时间:2016-04-24 06:20:29.0
如何根据某一变量,执行不同的select语句?
如何根据某一变量,执行不同的select语句?
2个select语句完全不同

------解决方案--------------------
SQL code
-- 用存储过程封装这两个SQL语句,然后调用存储过程:-- 存储过程传入一个参数:当参数为1时,执行SQL1;当参数为2时,执行SQL2create procedure sql_if_proc(sql_if number) isbegin  if sql_if=1 then    your_sql_here;  elsif sql_if=2 then    your_other_sql_here;  end if;end;/
------解决方案--------------------
select * from aa ....
where 'a' = :变量
and .......
union all
select * from bb ....
where 'a' <> :变量
and .....

--------------------------------------

select * from aa ....
where 1 = :变量
and .......
union all
select * from bb ....
where 2 = :变量
and .....

有什么不一样。
  相关解决方案