无法在表空间 TEMP 中将临时段扩展 128

unable to extend temp segment by 128 in tablespace TEMP

我正在尝试在 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.

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

    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

知道如何解决吗?

谢谢, 阿鲁纳

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

具体而言,您编写 WHERE 子句谓词的方式。我怀疑前三个谓词是您的连接谓词,后四个谓词应该限制要连接到的课程 table 中的行。

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

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

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 语句组合在一起,然后将它们与其余谓词进行 AND 运算。

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.

的前进方向