无法在表空间TEMP

时间:2017-02-13 14:24:53

标签: oracle oracle-sqldeveloper temp segment tablespace

我正在尝试在Oracle中执行以下查询:

SELECT DISTINCT
   t4.s_studentreference "Student ID",
  t3.p_surname "Surname",
  t3.p_forenames "Forenames",
t1.m_reference "Course",
 t2.e_name "Enrolment Name"
 FROM student t4,
  person t3,
  enrolment t2,
  course t1
WHERE t4.s_id(+) =t3.p_id
AND (t2.e_student=t3.p_id)
AND (t2.e_course =t1.m_id)
AND (t1.m_reference LIKE 'LL563%15')
OR (t1.m_reference LIKE 'LL562%15')
OR (t1.m_reference LIKE 'LL563%16')
OR (t1.m_reference LIKE 'LL562%16')

但是,我收到了以下错误:

ORA-01652: unable to extend temp segment by 128 in tablespace TEMP
01652. 00000 -  "unable to extend temp segment by %s in tablespace %s"
*Cause:    Failed to allocate an extent of the required number of blocks for
           a temporary segment in the tablespace indicated.
*Action:   Use ALTER TABLESPACE ADD DATAFILE statement to add one or more
           files to the tablespace indicated.

我使用下面的查询来查找临时段空间:

    select inst_id, tablespace_name, total_blocks, used_blocks, free_blocks
 from gv$sort_segment;

给予:

INST_ID, TABLESPACE_NAME, TOTAL_BLOCKS, USED_BLOCKS, FREE_BLOCKS
1           TEMP           3199872       15360         3184512

知道如何解决?

谢谢, 阿鲁娜

1 个答案:

答案 0 :(得分:7)

虽然标准答案是让您的DBA扩展TEMP表空间,但我认为问题在于您的查询。

具体来说,您编写WHERE子句谓词的方式。我怀疑前三个谓词是你的连接谓词,后四个应该限制从连接到的课程表中的行。

然而,正在发生的事情是前四个谓词被首先计算(因为AND优先于OR)并且我怀疑这会导致你的连接出现一些问题 - 可能是一些意外的交叉连接,这可能是什么意外地炸毁了你的TEMP表空间。

为防止这种情况发生,您有两种可能的解决方案:

<强> 1。在正确的位置用括号澄清您的AND / OR逻辑:

SELECT DISTINCT
       t4.s_studentreference "Student ID",
       t3.p_surname "Surname",
       t3.p_forenames "Forenames",
       t1.m_reference "Course",
       t2.e_name "Enrolment Name"
FROM   student t4,
       person t3,
       enrolment t2,
       course t1
WHERE  t4.s_id(+) = t3.p_id
AND    t2.e_student = t3.p_id
AND    t2.e_course = t1.m_id
AND    (t1.m_reference LIKE 'LL563%15'
        OR t1.m_reference LIKE 'LL562%15'
        OR t1.m_reference LIKE 'LL563%16'
        OR t1.m_reference LIKE 'LL562%16');

上面将所有OR语句组合在一起,然后将它们与其余的谓词进行对比。

<强> 2。使用ANSI连接语法并从连接谓词中分离出搜索谓词:

SELECT DISTINCT
       t4.s_studentreference "Student ID",
       t3.p_surname "Surname",
       t3.p_forenames "Forenames",
       t1.m_reference "Course",
       t2.e_name "Enrolment Name"
FROM   student t4,
       RIGHT OUTER JOIN person t3 ON t4.s_id = t3.p_id
       INNER JOIN enrolment t2 ON t3.p_id = t2.e_student 
       INNER JOIN course t1 ON t2.e_course = t1.m_id
WHERE  t1.m_reference LIKE 'LL563%15'
OR     t1.m_reference LIKE 'LL562%15'
OR     t1.m_reference LIKE 'LL563%16'
OR     t1.m_reference LIKE 'LL562%16';

当然,当你在where子句中混合使用AND和OR时,后者并不排除在正确位置使用括号...

选项2将是我的首选解决方案 - ANSI连接语法实际上是编写SQL时的前进方式。