使用Delphi 7,BDE和Oracle
我执行SQL select语句,然后逐步执行返回集的每个记录并执行以下更新sql
var
AQuery: TQuery;
begin
AQuery:= TQuery.Create(nil);
AQuery.DatabaseName:= ADatabase.DatabaseName;
with AQuery do
begin
SQL.Text:= 'UPDATE AP_Master SET CMCL_FORECAST_CLEARED=:AClearedDate WHERE ID=:AMasterId';
ParamByName('AMasterId').AsString:= IntToStr(AId);
ParamByName('AClearedDate').AsDateTime:= StrToDateTime(FormatDateTime('mm/dd/yyyy', AForeCastClearedDate));
try
ExecSql;
except on E: Exception do
begin
raise Exception.create('Error Updating AP_Master Tables Forecast Cleared Date!' + E.Message);
end;//except
end; //try
end; //with
AQuery.Close;
AQuery.Free;
end;
它适用于最终的500 +记录,但我得到一个:ORA-01000:最大打开游标超出消息
我是否需要在BDE端,oracle端或我的代码中使用(我使用标准的TQuery和TDatabase组件)
答案 0 :(得分:3)
您的查询结果不合适,这意味着您是每行的孤立游标。试试这个:
var
AQuery: TQuery;
begin
AQuery:= TQuery.Create(nil);
try
AQuery.DatabaseName:= ADatabase.DatabaseName;
with AQuery do
begin
SQL.Text:= 'UPDATE AP_Master'#13 +
'SET CMCL_FORECAST_CLEARED = :AClearedDate'#13 +
'WHERE ID= :AMasterId';
ParamByName('AMasterId').AsInteger := AId;
// Note the date->string->date is not necessary; setting the param
// AsDateTime with a TDateTime value will format it correctly for you.
ParamByName('AClearedDate').AsDateTime:= AForeCastClearedDate;
try // Protect open
try
ExecSql;
except
on E: Exception do
raise Exception.create('Error Updating AP_Master Tables' +
' Forecast Date Cleared' +
E.Message);
end;//except
end; // except try
finally
AQuery.Close; // finally means it's closed every time always
end; //finally try for opening
end; //with
finally
AQuery.Free; // finally here ensures free
end;
end;