如不考虑效率,可以用一个sql实现
select b.b1, b.b2, b.b3
from (select decode(a3, '1','%1', '2','20', '3','31', '4','41', 'xx') newa3
from a
where a.a1='IP' and a.a2='IP地址') a,
(select b.b1, b.b2, b.b3,
decode(b1, '55','41', '45','31', '32','20', '23','20', '01') newb1
from b) b
where b.newb1 like a.newa3;
或者
select b.b1, b.b2, b.b3
from a, b
where (a.a1='IP' and a.a2='IP地址')
and ( (a.a3='1' and b.b1 not in ('32','23'))
or(a.a3='2' and b.b1 in ('32','23'))
or(a.a3='3' and b.b1='45')
or(a.a3='4' and b.b1='55') )
select b.b1, b.b2, b.b3
from (select decode(a3, '1','%1', '2','20', '3','31', '4','41', 'xx') newa3
from a
where a.a1='IP' and a.a2='IP地址') a,
(select b.b1, b.b2, b.b3,
decode(b1, '55','41', '45','31', '32','20', '23','20', '01') newb1
from b) b
where b.newb1 like a.newa3;
或者
select b.b1, b.b2, b.b3
from a, b
where (a.a1='IP' and a.a2='IP地址')
and ( (a.a3='1' and b.b1 not in ('32','23'))
or(a.a3='2' and b.b1 in ('32','23'))
or(a.a3='3' and b.b1='45')
or(a.a3='4' and b.b1='55') )
解决方案 »
- [求助]关于在windows下面用bat文件备份数据库的问题
- 如何对ORACLE里的CLOB字段进行模糊查询?例如like关键字可以用吗?
- 一条SQL语句的优化,在线等(急),多谢各位了.
- Oracle10g在RedHat AS4 x86_64安装报错~~
- 查数据库中所有表的名称
- 这里我不用游标用什么?
- 装oracle9i时:要想安装pl/sql 按照哪个安装选项安装?
- 急:导入数据时,表间有关联且有数据怎么才能把新表数据导进去!!!!
- 十分着急,游标出错怎么办?
- oracle往导入数据时需要的表空间变得很大导致导入中断
- 求两段VB示例代码:用VB备份、及恢复ORACLE数据库。想要数据库在打开状态下也能进行的热备份
- [学习方法] 知道函数名想知道函数的功能 在哪能查到?
(select a3 from a where a1='ip' and a2='地址')='1' and b1 not in ('32','33')
union
select * from b where
(select a3 from a where a1='ip' and a2='地址')='2' and b1 in ('32','33')
union
select * from b where
(select a3 from a where a1='ip' and a2='地址')='3' and b1='45'
union
select * from b where
(select a3 from a where a1='ip' and a2='地址')='4' and b1='55'
写存储过程吧
where (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '1') and b1 not in ('32','23'))
or (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '2') and b1 in ('32','23'))
or (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '3') and b1 in ('45'))
or (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '4') and b1 in ('55'))