【问题标题】:using Global Temporary table in a Job在作业中使用全局临时表
【发布时间】:2011-12-14 18:25:08
【问题描述】:

我正在研究一个 PL-SQL 存储过程,该过程将根据日常工作运行。 在存储过程中,我尝试使用这样的全局临时表:

CREATE GLOBAL TEMPORARY TABLE A_Table 
ON COMMIT PRESERVE ROWS 
AS SELECT * from B_Table

然后我会尝试创建这样的索引:

CREATE INDEX idx_a ON A_Table (id)

我有两个问题:

  1. 我创建的表始终为空:因此存储过程中的所有计算都将为零。
  2. 当我尝试创建索引时出现此错误:

    ORA-14452:尝试在已使用的临时表上创建、更改或删除索引

有什么建议吗??

最好的问候

【问题讨论】:

    标签: oracle plsql oracle9i temp-tables


    【解决方案1】:
      1234563如果您想在会话之间存储数据,请使用普通表。
    1. 关闭使用临时表的会话,然后重试。

    【讨论】:

      【解决方案2】:
      1. 您创建的表可能不是空的,但仅用于填充它的会话。可以说,每个会话都有自己的临时表实例。顺便说一下,这是临时表的主要功能。

      2. 修改温度。表是不可能的,而曾经使用过它的任何会话都处于活动状态(可能未处于活动状态)

      【讨论】:

        【解决方案3】:

        您提到您正在创建临时表,但大概您已经创建了一次,并且没有尝试在每次 plsql 代码运行时重新创建它,并且索引定义可以保留在临时表上 - 这也不需要创建每次运行代码。

        全局临时表具有静态定义 - 您只需创建它,它就在那里,但它不会生成重做/撤消,并且其中包含的数据仅对填充它的会话可见。

            SQL*Plus: Release 10.1.0.4.2 - Production on Wed Oct 26 01:22:30 2011
        
            Copyright (c) 1982, 2005, Oracle.  All rights reserved.
        
        
            Connected to:
            Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
        
            SQL> create global temporary table test (name varchar2(20));
        
            Table created.
        
            SQL> insert into test values ('one');
        
            1 row created.
        
            SQL> insert into test values ('two');
        
            1 row created.
        
            SQL> select * from test;
        
            NAME
            --------------------
            one
            two
        

        然后在另一个会话中

            SQL*Plus: Release 10.1.0.4.2 - Production on Wed Oct 26 01:23:17 2011
        
            Copyright (c) 1982, 2005, Oracle.  All rights reserved.
        
        
            Connected to:
            Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
        
            SQL> select * from test;
        
            no rows selected
        
            SQL> insert into test values ('three');
        
            1 row created.
        
            SQL> select * from test;
        
            NAME
            --------------------
            three
        

        回到第一个会话 SQL> 提交;

            Commit complete.
        
            SQL> select * from test;
        
            no rows selected
        
            SQL> drop table test;
            drop table test
                       *
            ERROR at line 1:
            ORA-14452: attempt to create, alter or drop an index on temporary table already
            in use
        

        因为我们在第二个会话中插入了数据,所以我们不能对临时表做任何事情 直到我们在第二个会话中提交,然后 drop 成功

        您可以选择在提交时(在提交删除行时)或保留数据直到会话终止(在提交保留行时)为创建它的会话清除内容。

        【讨论】:

          猜你喜欢
          • 2023-04-08
          • 1970-01-01
          • 1970-01-01
          • 2010-12-07
          • 2017-10-02
          • 2023-03-27
          • 1970-01-01
          • 1970-01-01
          • 2015-12-11
          相关资源
          最近更新 更多