1的错应该是语法错,你是不是在什么地方丢了分号或别的什么
2的错是这样,temp_table的类型是一提交就删除数据,而create global temporary table temp_table on commit delete rows as select * from tablename创建表的时候就插入数据并且马上提交,在我这里执行这条语句时会报个错ora-25153 temporary tablespace is empty,并且表也建不起来解决办法是
create global temporary table temp_table on commit delete rows as 
select * from tablename where 1=2;
这样只建表不插入记录

解决方案 »

  1.   

    谢谢 gladness(gladness) 
    我仔细检查了第一种方法,没发现语法错误
    第二种方法今天再试,提示PLS-00201,必须说明标识符‘temp_table' 
    很奇怪
      

  2.   

    别客气,你的这两句话是放在哪里执行的?
      create_sql := 'create global temporary table temp_table on commit delete rows as select * from tablename' ;
    execute immediate create_sql ; 
    也应该放在存储过程或匿名块中执行,你是怎么执行的?把完整的帖出来看看.你的数据库版本 是多少,我是在9i里试的没问题
      

  3.   

    数据库是7.3
    在oracle 中执行的。第一个如下:
    create or replace procedure temporary_table_test
    is
    create_sql varchar2(500) ;
    create_sql := 'create global temporary table temp_table on commit delete rows as select * from tablename' ;
         execute immediate create_sql ;  第二个如下:
    create or replace procedure temporary_table_test
    is
    create_sql varchar2(50) ;
    source_cursor integer ;
    install_lan_E1A integer ;
    begin
    begin
       create_sql := 'create global temporary table temp_table on commit delete rows as select * from tablename where 1= 2' ;
       source_cursor := DBMS_SQL.OPEN_CURSOR;
       DBMS_SQL.PARSE(source_cursor, create_sql, DBMS_SQL.native); 
       
       select count(*) into install_lan_E1A from temp_table ;   DBMS_SQL.CLOSE_CURSOR(source_cursor); 
    end ;
        
    end temporary_table_test;
      

  4.   

    create or replace procedure temporary_table_test
    is
    create_sql varchar2(500) ;
    begin  --原文中缺了
    create_sql := 'create global temporary table temp_table on commit delete rows as select * from tablename' ;
    execute immediate create_sql ;
    end; --原文中缺了但是不知道7.3支持不支持临时表?
      

  5.   

    问题一:
    数据库是7.3不支持execute immediate 
    问题二:
    动态创建临时表,与表空间有关系,两种方案1、本地+临时,2、字典+永久
      

  6.   

    再次谢谢gladness(gladness)beckhambobo(beckham),对于问题二能不能详细点,在连机帮助上好象没这么讲?
      

  7.   

    PERMANENT | TEMPORARY
    PERMANENT 
     Specify PERMANENT if the tablespace will be used to hold permanent objects. This is the default. 
     
    TEMPORARY 
     Specify TEMPORARY if the tablespace will be used only to hold temporary objects, for example, segments used by implicit sorts to handle ORDER BY clauses. Restriction: If you specify TEMPORARY, you cannot specify EXTENT MANAGEMENT LOCAL. 
     DICTIONARY 
     Specify DICTIONARY if you want the tablespace to be managed using dictionary tables. This is the default. 
     
    LOCAL 
     Specify LOCAL if you want the tablespace to be locally managed. Locally managed tablespaces have some part of the tablespace set aside for a bitmap.
     
    1、DICTIONARY+PERMANENT  2、LOCAL+TEMPORARY
    参考:http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a85397/statem4c.htm#2063129