在Oracle中,如何将查询出的数据存入临时表中

[复制链接]
查看11 | 回复3 | 2010-5-11 11:48:29 | 显示全部楼层 |阅读模式
create global temporary table abcd as select a.a1,b.b2 from a,b where a.id=b.id 这个语句执行后表中没内容。
create global temporary table abcd as select a.a1,b.b2 from a,b where a.id=b.id on commit delete rows;这个语句在Oracle 10g中执行时会出现“命令未正确结束”的错误,希望高手指点。如果正确,我会多加15分,因为我就这么多了。
是在sql*plus中

回复

使用道具 举报

千问 | 2010-5-11 11:48:29 | 显示全部楼层
temporary table :临时表,有两种方法1、on commit delete rows;当COMMIT的时候删除数据2、on commit preserve rows;当COMMIT的时候保留数据当不写的时候默认为1。所以你的第一条语名自然没有数据。但你如果在程序中使用的话此临时表的数据的生命周期就是本程序开始至结束。第二条语句要变为:create global temporary table abcd on commit delete rows as select a.a1,b.b2 from a,b where a.id=b.id ;
回复

使用道具 举报

千问 | 2010-5-11 11:48:29 | 显示全部楼层
比如临时表叫temp,你要查询的语句为select * from 表名 where id=1。如果temp表存在:insert into temp select * from 表名 where id=1;commit;如果temp表不存在create table temp as insert into temp select * from 表名 whe
回复

使用道具 举报

千问 | 2010-5-11 11:48:29 | 显示全部楼层
临时table在commit后都看不到数据吧。create动作又是那种默认commit的。所以, 在后面的insert 动作后,应该是可以看到。create global temporary table abcdon commit delete rows as select a.a1,b.b2 from a,b where a.id=b.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行