insert into tmptable select * from tablename

解决方案 »

  1.   

    是要产生一个表,还是要临时存储数据 
     create table table_name as select * from tablename;
      

  2.   

    申明转贴:不记得作者(抱歉);11:25:05 SQL> create or replace procedure pro_temp(v_col1 varchar2,v_col2 varchar2) as
    11:25:05   2  v_num number;
    11:25:05   3  begin
    11:25:05   4  select count(*) into v_num from user_tables where table_name='T_TEMP';
    11:25:05   5  --create temporary table
    11:25:05   6  if v_num<1 then
    11:25:05   7    execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (
    11:25:05   8     COL1  VARCHAR2(10),
    11:25:05   9     COL2  VARCHAR2(10)
    11:25:05  10     ) ON COMMIT PRESERVE ROWS';
    11:25:05  11  end if;
    11:25:05  12  --insert data
    11:25:05  13  execute immediate 'insert into t_temp values('''||v_col1||''','''||v_col2||''')';
    11:25:05  14  end pro_temp;
    11:25:06  15  /过程已创建。已用时间:  00: 00: 00.4411:27:31 SQL> exec pro_temp('11','22');PL/SQL 过程已成功完成。已用时间:  00: 00: 00.43
    11:27:41 SQL> select * from t_temp;COL1       COL2
    ---------- ----------
    11         22已用时间:  00: 00: 00.16
    11:27:47 SQL> 当前session 断开以后,数据自动清空。
      

  3.   

    我的意思是这样:我想从一个现有的A表中生成一个与A表的结构和数据都一模一样的B表,但如果我
    断开当前与数据库的连接,B表就自然消失。
    能否实现?
      

  4.   

    临时表当用户会话结束时,数据会自动删除, 但也分为2中类型的临时表:
    create global temporary table 表名 (字段名 类型) on commit preserve rows;
    当COMMIT时数据保留~
    create global temporary table 表名 (字段名 类型) on commit delete rows
    当COMMIT时数据删除~例1:
    SQL> create global temporary table aa (c1 number) on commit preserve rows;Table created.SQL> insert into aa values (11);1 row created.SQL> commit;Commit complete.SQL> select * from aa;        C1
    ----------
            11
    SQL> exit
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining option
    s
    JServer Release 9.2.0.1.0 - ProductionC:\>sqlplus scott/tigerSQL*Plus: Release 9.2.0.1.0 - Production on 星期三 12月 15 13:20:16 2004Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining option
    s
    JServer Release 9.2.0.1.0 - ProductionSQL> select * from aa;no rows selectedSQL>
    例2:
    SQL> create global temporary table bb (c1 number) on commit delete rows;Table created.SQL> insert into bb values (11);1 row created.SQL> select * from bb;        C1
    ----------
            11SQL> commit;Commit complete.SQL> select * from bb;no rows selectedSQL>
      

  5.   

    在Oracle8i中,可以创建以下两种临时表: 
    1。会话特有的临时表 
    CREATE GLOBAL TEMPORARY <TABLE_NAME> (<column specification> ) 
    ON COMMIT PRESERVE ROWS; 2。事务特有的临时表 
    CREATE GLOBAL TEMPORARY <TABLE_NAME> (<column specification> ) 
    ON COMMIT DELETE ROWS; 
    CREATE GLOBAL TEMPORARY TABLE MyTempTable 
    所建的临时表虽然是存在的,但是你试一下insert 一条记录然后用别的连接登上去select,记录是空的,明白了吧。
    下面两句话再贴一下: 
    --ON COMMIT DELETE ROWS 说明临时表是事务指定,每次提交后ORACLE将截断表(删除全部行) 
    --ON COMMIT PRESERVE ROWS 说明临时表是会话指定,当中断会话时ORACLE将截断表。
    这种临时表不占用表空间,而且不同的SESSION之间互相看不到对方的数据
    在会话结束后表中的数据自动清空,如果选了DELETE ROWS,则在提交的时候即清空数据,PRESERVE则一直到会话结束
      

  6.   

    Oracle在这方面做得还是没有Sybase好
      

  7.   

    create table a select * from b;....
    drop table a;
      

  8.   

    楼上的,这个不是跟SYBASE一样吗?你的目的是不要占用空间,Oracle这样的临时表也做到了啊。