无法在表空间TEMP中将临时段扩展128。执行该查询的另一种选择?

时间:2016-10-05 08:11:47

标签: oracle tablespace

我是Oracle SQL的新手,我正在尝试使用下一个上下文更新表:

我有一张桌子A:

+---------+---------+---------+----------+
| ColumnA | name    | ColumnC | Column H |
+---------+---------+---------+----------+
| 1       | Harry   |  null   | null     |
| 2       | Harry   |  null   | null     |
| 3       | Harry   |  null   | null     |
+---------+---------+---------+----------+

表B:

+---------+---------+---------+
| name    | ColumnE | ColumnF |
+---------+---------+---------+
| Harry   | a       |  d      |
| Ron     | b       |  e      |
| Hermione| c       |  f      |
+---------+---------+---------+

我想更新表格A,结果将是下一个:

+---------+---------+---------+----------+
| ColumnA | name    | ColumnC | Column H |
+---------+---------+---------+----------+
| 1       | Harry   |  a      | d        |
| 2       | Harry   |  a      | d        |
| 3       | Harry   |  a      | d        |
+---------+---------+---------+----------+

我遇到了Oracle SQL语句的问题。我有下一个背景:

merge into tableA a
using tableB b
on (a.name=b.name)
when matched then update set
columnC = b.columnE,
columnH = b.columnF


create table tableA (columnC varchar2(20), columnH varchar2(20), name varchar2(20), columnA number);
create table tableB (columnE varchar2(20), columnF varchar2(20), name varchar2(20));
insert into tableA values (null, null,'Harry',1);
insert into tableA values (null, null,'Harry',3);
insert into tableA values (null, null,'Harry',3);
insert into tableB values ('a', 'd','Harry');
insert into tableB values ('b', 'e','Ron');
insert into tableB values ('c', 'f','Hermione');
select * from tableA;
merge into tableA a
using tableB b
on (a.name=b.name)
when matched then update set
columnC = b.columnE,
columnH = b.columnF;
select * from tableA;

问题是当我执行该命令时出现下一个错误:

  

错误:ORA-01652:无法在表空间中将临时段扩展128   TEMP

我无法为TEMP表空间提供更多空间。所以,我的问题是:是否有任何选项可以使用另一个不使用TEMP表空间的SQL查询?

1 个答案:

答案 0 :(得分:2)

你可以尝试以下查询,也许它会消耗更少的TEMP表空间:

update tableA 
set (columnC, columnH ) = (select ColumnE, ColumnF from tableB where tableB.name = tableA.name)
where 
  tableA.name in (select tableB.name from tableB)
;

或者您可以尝试在循环中以小块执行更新。它的性能较差,但如果你没有别的办法......

    begin 
      FOR rec in 
      (select name, ColumnE, ColumnF from tableB)
      LOOP
       update tableA 
       set  
         columnC = rec.columnE
        , columnH = rec.columnF
       where name = rec.name
       ;
      end loop;
    end;
 /