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能在客户端用吗.我怎么用不起来.

解决方案 »

  1.   

    'insert into '之前,先执行删除操作,'delete from tempp'
      

  2.   

    是为了第二次按下Button1后以前的数据要清除,然后重新插入数据。临时表不是会自动清除吗,我怎么能实现在第二次按下Button1后临时表的数据是空的。
      

  3.   

    oracle中的临时表分为事务型和对话型的,
    你所创建的是对话型的临时表,如果事务型的用on commit delete rows来创建这样你在每次按完按钮Button1后,要加一个commit用事务来控件,这时临时表会自动清空的,
    否则你每次要先执行一下清空的操作(因为你在一个会话中,当关闭这个窗体后会自动清空)
      

  4.   

    我用过on commit delete rows来创建的,但是什么数据也没查出来,能不能帮忙看看是不是我的语句有问题。
      

  5.   

    procedure TForm1.Button1Click(Sender: TObject);
    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;你这样测一下,我试了,没有问题
      

  6.   

    非常感谢,不过我用的是dbexpress不是ado不知会不会有什么不同。
      

  7.   

    除非是控件BUG -_-反正我用DOA访问临时表是没问题,就是注意楼上说的会话后是否删除数据的那个选项的设置