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

decode在SQL中应用

2012-08-30 
decode在SQL中使用select * from table1 where decode(nvl(变量1,),1,name) (case when nvl(变量1,)

decode在SQL中使用
select * from table1
where decode(nvl(变量1,''),1,name) =   (case when nvl(变量1,'') = '' then 1 else 变量1 end)
  and decode(nvl(变量2,''),1,sex)  =   (case when nvl(变量2,'') = '' then 1 else 变量2 end)

select * from table1
where decode(&变量1,'','0000',name) =   (case when nvl(&变量1,'') is null then '0001' else &变量1 end)
   or decode(&变量2,'','0000',sex)  =   (case when nvl(&变量2,'') is null then '0001' else &变量2 end)
   or (decode(&变量1,'','0000',name) =   (case when nvl(&变量1,'') is null then '0000' else &变量1 end)--当变量1,变量2都为空时,显示所有
       and decode(&变量2,'','0000',sex)  =   (case when nvl(&变量2,'') is null then '0000' else &变量2 end))

热点排行