Chinaunix首页 | 论坛 | 博客
  • 博客访问: 536998
  • 博文数量: 154
  • 博客积分: 4055
  • 博客等级: 上校
  • 技术积分: 1381
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-01 14:26
文章分类

全部博文(154)

文章存档

2014年(2)

2013年(2)

2011年(2)

2010年(11)

2009年(9)

2008年(35)

2007年(22)

2006年(71)

我的朋友

分类: Oracle

2006-07-31 13:57:00

已开始我在数据库里写了一条sql

select  cust.id cust_id,
         acct.id acct_id,
         serv.id serv_id
from serv serv
left outer join acct acct on acct.acctid=serv.acctid
left outer join cust cust on acct.custid=cust.custid
where serv.Devcode =
'8834288'

在数据库里查询的时候,不知道怎么回事,总是出现ora-03113的错误,通信通道文件结束,后来我就把此sql修改了一下

select  cust.id cust_id,
         acct.id acct_id,
         serv.id serv_id
from serv serv ,acct acct,cust cust
 where serv.Devcode =
'8834288'

and serv.acctid=acct.acctid(+)

and acct.custid=cust.custid(+)

这个时候还是出现那个错误,怎么回事呢,后来无意间我又改成

select  cust.id cust_id,
         acct.id acct_id,
         serv.vid serv_id
from serv serv ,acct acct,cust cust
 where serv.Devcode =
'8834288'

and serv.acctid=acct.acctid(+)

and acct.custid=cust.custid(+)

这个时候可以查询了,并且速度还挺快的,0.6秒左右,于是我就去查cust,acct,serv的表结构

这时候我发现acctserv上没有主键,只有cust上有主键

我就试着修改成了

select  cust.id cust_id,
         acct.acctid acct_id,
         serv.servid serv_id
from serv serv ,acct acct,cust cust
 where serv.Devcode =
'8834288'

and serv.acctid=acct.acctid(+)

and acct.custid=cust.custid(+)

又出现了原来的那个通行通道的错误,我又改成了

select  cust.custid cust_id,
         acct.id acct_id,
         serv.servid serv_id
from serv serv ,acct acct,cust cust
 where serv.Devcode =
'8834288'

and serv.acctid=acct.acctid(+)

and acct.custid=cust.custid(+)

发现速度很快,于是断定是cust中主键在作怪,于是我把cust的主键取消了,速度突然很快了,但是主键不能没有的,由于在cust,acct,serv表中  

Cust.id=cust.custid

Acct.id=acct.acctid

Serv.id=serv.servid

所以,我又改成了

select  cust.custid cust_id,
         acct.acctid acct_id,
         serv.servid serv_id
from serv serv ,acct acct,cust cust
 where serv.Devcode =
'8834288'

and serv.acctid=acct.acctid(+)

and acct.custid=cust.custid(+)

此时速度很快,问题解决了

呵呵,但是我还不知道问什么按主键查询,怎么会那么慢,请那位大虾帮帮忙了

其中custid,acctid,servid 都是索引

 

 

阅读(3125) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~