向数据库表中查入数据,POST时非常慢--急(在线等),各位大虾进来帮帮忙,万分感谢(100分)

  • 主题发起人 主题发起人 wlggslz
  • 开始时间 开始时间
W

wlggslz

Unregistered / Unconfirmed
GUEST, unregistred user!
由于表中数据非常多,大概有几个G左右,提交的时候非常慢,有什么方法可以解决<br> 例如  table1.table='picture' <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.open;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.append;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ......<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ......<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.post; <br>在运行到table1.post就过不去了,特别是第1次提交的时候慢的不可想象
 
而我新建一张表后,数据的存储就正常了,表是没有问题的,也有索引,有什么好的办法,各位大虾帮帮忙,谢谢
 
上百G的数据,你厉害!
 
数据存储到几个G以上的时候就非常慢了,这个表里面有几个字段是存储图片的
 
不知道你是如何连,接试一下下面的方法<br>1、 &nbsp; &nbsp; &nbsp; table1.DisableControls;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.table='picture' <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.open;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.append;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ......<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ......<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.post; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; table1.EnableControls;<br>2、 够500记录才post一次
 
数据多,table open一次就够满了<br>如果只插入用query也可以
 
dm1.vehqry.SQL.add('insert into veh_picture (xh,pic,gxsj) values (:xh,:zp,:hpzl,:hphm,sysdate)');<br>&nbsp; &nbsp;dm1.vehqry.ParamByName('xh').Value :=dm1.docmg.fieldbyname('xh').asstring;<br>&nbsp; &nbsp; &nbsp;ss:=dm1.docmg.CreateBlobStream(tblobfield(dm1.docmg.FieldByName('pic')),bmread);<br>&nbsp; &nbsp;dm1.vehqry.ParamByName('pic').AsBlobref.LoadFromStream(ss);<br>&nbsp; &nbsp;dm1.vehqry.Execute;<br>&nbsp; &nbsp;dm1.vehcon.Commit;<br>这种方法我也试过了,还是不行啊,第1次几分钟的时间都插不进去,我用的是oracle数据库,连接控件是odac
 
这么好的技术论坛怎么变成某些人做广告的基地了?没有人出来管理一下吗
 
不建议用Ttable类,用Query好一点,<br>插入数据时和表的索引关系不大<br>建议Open一次,然后都用过程<br>try<br>&nbsp; ado.BeginTrans;<br>&nbsp; while not eof do<br>&nbsp; begin<br>&nbsp; &nbsp; qy.append;<br>&nbsp; &nbsp; qy.fiel........ &nbsp; &nbsp;<br>&nbsp; &nbsp; qy.post<br>&nbsp; end<br>&nbsp; ado.CommitTrans; &nbsp;//最后提交一次<br>&nbsp;except<br>&nbsp; ado.RollbackTrans;//报错的话回G<br>end;
 
用table控件当数据相当大的时候是个问题,因为他在open的时候就会耗费大量资源,<br>而且数据不是成批量插入,而是一条一条的插入的,一笔业务插入一条数据,每条数据都带有图片信息,还是用query实现的好,不过我用的是odac第三方控件
 
各位大虾,用过odac的指点一下<br>&nbsp; &nbsp;dm1.vehqry.SQL.add('insert into veh_picture (xh,pic,gxsj) values (:xh,:zp,:hpzl,:hphm,sysdate)');<br>&nbsp; &nbsp;dm1.vehqry.ParamByName('xh').Value :=dm1.docmg.fieldbyname('xh').asstring;<br>&nbsp; &nbsp; &nbsp;ss:=dm1.docmg.CreateBlobStream(tblobfield(dm1.docmg.FieldByName('pic')),bmread);<br>&nbsp; &nbsp;dm1.vehqry.ParamByName('pic').AsBlobref.LoadFromStream(ss);<br>&nbsp; &nbsp;dm1.vehqry.Execute;<br>&nbsp; &nbsp;dm1.vehcon.Commit;<br>我上面的语句在存储图片的时候有问题,在运行到dm1.vehqry.exceute时报错
 
with oraupdate do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; close;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sql.Clear;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sql.text:='update veh_picture set hpzl=:hp,zp=:zp where xh=:xh';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parambyname('hp').value :='01';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parambyname('xh').value :='22222222222';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ss:=dm1.DocMg1.CreateBlobStream(tblobfield(dm1.DocMg1.FieldByName &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;('pic')),bmread);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ss.Position:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parambyname('zp').asblobref.LoadFromStream(ss);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; execsql;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dm1.VehCon.Commit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>流SS是有值的,通过imageenview控件可以显示图片,但是图片没有插入到数据库,请问各位大虾到底是怎么回事 SS为TStream变量 查询控件为odac中的oraquery控件
 
我觉得是不是从思路上理顺一下。首先这种方式有没有问题,新建个表的话如果可以,建的字段和实际用的一样么?还有就是是不是要入库的图片的表有没有触发器之类的,执行失败回滚了。若新建的表可以,那这种方试就没问题,那就是考虑实际环境和新建表的执行环境有什么不同了。我做过的是sql server ,mysql的数据存储,oracle的到没用过。
 
这个问题那天下午我找出原因了,ODAC控件有问题啊,在执行LoadFromStream时,调用的基类有问题,过不去,而OoaTable可以通过,但是表数据过多太耗费资源,我最后没办法用adocommand做的,这是没办法的事情,在客户端还要配置oracle的本地服务名,就是有点烦琐
 
后退
顶部