SQL判空问题

zty_zty123 2013-01-16 04:12:12
select username
from (select distinct substr(c.circuitname,
0,
(instr(c.circuitname, '_', 1, 1)) - 1) username
from node n, userinfo u, device d, portinfo p, circuit c
where u.netuserid = 'admin'
and n.nodefullcode like '%' || u.nodecode || '%'
and d.nodecode = n.nodecode
and d.changetype = 0
and c.changetype = 0
and p.deviceid = d.deviceid
and ((c.adeviceid = d.deviceid and c.aintdescr = p.portdescr) or
(c.bdeviceid = d.deviceid and c.bintdescr = p.portdescr)))
where username is not null//加了这句后比不加慢了几十倍,请教各位高手,谢谢
...全文
413 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Galen_Gao 2013-01-22
  • 打赏
  • 举报
回复
yuyeyi 2013-01-22
  • 打赏
  • 举报
回复
username = decode(username,null,-1,username)
sohay1984 2013-01-21
  • 打赏
  • 举报
回复
请把增加where条件和不加where条件的2中sql 执行计划贴出来看看?
huyaowu001 2013-01-21
  • 打赏
  • 举报
回复
这个设计是不是有问题呢,一下子要关联这么多表。
wjj_cadn 2013-01-20
  • 打赏
  • 举报
回复
为什么奥嵌套循环查询 呢?个人认为 一句一句分开 比较好,用到临时表,空间换时间
土匪八号 2013-01-18
  • 打赏
  • 举报
回复
from node n, userinfo u, device d, portinfo p, circuit c 你怎么可以一个from中出现多个表那,这样速度很慢的 要两个两个的拼接,,这样效率应该可以提高很多
foolish_cc1986 2013-01-18
  • 打赏
  • 举报
回复
null是不走索引的,总和考虑下,是否有必要建立个函数索引,这样null也能走索引。
fjmwish 2013-01-18
  • 打赏
  • 举报
回复
我看了之后呢 觉得 是 有 两个原因 引起的 1.是 你 select 子连接 查询 而且 有用了 好多个 wher 条件 效率 本来就很低 ,你现在有 增加 了 条件 is not null 他们 这个 语句是有 执行顺序的 ,而且 这个 语句 本来 的 效率 也是 比较低的 ,他从数据库 中 取一个 比一个 肯定是 慢了。
zhangabc 2013-01-17
  • 打赏
  • 举报
回复
条件加在子查询里 c.circuitname is not null 试试呢?
ajune 2013-01-17
  • 打赏
  • 举报
回复
我感觉应该是判断是否为null这个步骤的消耗比较大
UPC子夜 2013-01-16
  • 打赏
  • 举报
回复
username是个字符串类型的吧 先把所有为空的数据刷成‘0’ 然后加上where username > '0' 这样就可以临时处理了 后期的话,在check里给这个username附一个默认值,保证非空就可以了
zty_zty123 2013-01-16
  • 打赏
  • 举报
回复
有什么方法吗?我现在想着放到java里循环判断得了
我看见佛 2013-01-16
  • 打赏
  • 举报
回复
nvl(username,'')='' //这个也是不走索引的吧。好像没什么好方法。
Phoenix_99 2013-01-16
  • 打赏
  • 举报
回复
username is not null 不走索引

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧