首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

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

2012-01-14 
如何根据某一变量,执行不同的select语句?如何根据某一变量,执行不同的select语句?2个select语句完全不同[

如何根据某一变量,执行不同的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 .....

有什么不一样。

热点排行