CREATE GLOBAL TEMPORARY TABLE tempp (uni_no char(40) Primary key,item_name varchar2(100),price NUMber(7,2))
ON COMMIT PRESERVE ROWS
这样建好tempp临时表后,在delphi里这样操作
procedure TForm2.Button1Click(Sender: TObject);
var
ttt:string;
begin
ttt:='insert into tempp (uni_no,item_name,price) select uni_no,item_name,price from product where item_name like '+'%'+edit1.text+'%';
dm.Sdt.Active:=false;
dm.Sdt.DataSet.CommandText:=ttt;
dm.Sdt.Execute;
select * from bbb a,tempp b where a.uni_no=b.uni_no
dm.Sdt.Active:=false;
dm.Sdt.DataSet.CommandText:=ttt;
dm.Sdt.Active:=true;
当第二次按下Button1时报错,是因为tempp中的内容没清掉,请问怎样清tempp中的内容. trucate能在客户端用吗.我怎么用不起来.
ON COMMIT PRESERVE ROWS
这样建好tempp临时表后,在delphi里这样操作
procedure TForm2.Button1Click(Sender: TObject);
var
ttt:string;
begin
ttt:='insert into tempp (uni_no,item_name,price) select uni_no,item_name,price from product where item_name like '+'%'+edit1.text+'%';
dm.Sdt.Active:=false;
dm.Sdt.DataSet.CommandText:=ttt;
dm.Sdt.Execute;
select * from bbb a,tempp b where a.uni_no=b.uni_no
dm.Sdt.Active:=false;
dm.Sdt.DataSet.CommandText:=ttt;
dm.Sdt.Active:=true;
当第二次按下Button1时报错,是因为tempp中的内容没清掉,请问怎样清tempp中的内容. trucate能在客户端用吗.我怎么用不起来.
你所创建的是对话型的临时表,如果事务型的用on commit delete rows来创建这样你在每次按完按钮Button1后,要加一个commit用事务来控件,这时临时表会自动清空的,
否则你每次要先执行一下清空的操作(因为你在一个会话中,当关闭这个窗体后会自动清空)
begin
adoconnection1.BeginTrans;
try
with adoquery2 do
begin
close;
sql.text := 'insert into tempp values(:a,:b,:c)';
Parameters.ParamByName('a').Value := 'aa';
Parameters.ParamByName('b').Value := 'aa';
Parameters.ParamByName('c').Value := 100;
ExecSql;
end;
with adoquery1 do
begin
close;
sql.text := 'select * from tempp';
Open;
end;
adoconnection1.CommitTrans;
except
adoconnection1.RollbackTrans;
end;
end;你这样测一下,我试了,没有问题