我有以下查询,当我通过代码或Oracle SQL Developer执行该查询时,它可以正确返回记录。
SELECT TABLE_T.COL_P,
1234 AS COL_C,
TABLE_T.COL_D,
SUM(SOME_COLUMN) Value
FROM TABLE_T
INNER JOIN TABLE_E E ON TABLE_T.COL_P = E.COL_P
AND TABLE_T.COL_C = E.COL_C
AND TABLE_T.COL_CC = E.COL_CC
AND TABLE_T.COL_CL = E.COL_CL
INNER JOIN TABLE_C C1 ON C1.COL_P = E.COL_P
AND C1.COL_C = E.COL_C
INNER JOIN TABLE_C C2 ON C2.COL_P = C1.COL_P
AND C2.COL_CX = C1.COL_CX
AND C2.COL_CY = C1.COL_CY
AND C2.COL_CZ = C1.COL_CZ
WHERE TABLE_T.COL_P = 'Some Text'
AND C2.COL_C = 1234
AND TABLE_T.COL_CL IN
(SELECT COL_CL
FROM TABLE_CL
WHERE COL_P = 'Some Text'
AND ((COL_CLTYPE = 'VALUE_A')
OR (COL_CLTYPE = 'VALUE_B')
OR (COL_CLTYPE = 'VALUE_C')
OR (COL_CLTYPE = 'VALUE_D')) )
GROUP BY TABLE_T.COL_P,
TABLE_T.COL_D
但是,一旦执行以下会话命令,它就无法返回记录:
ALTER SESSION SET NLS_COMP = LINGUISTIC;
ALTER SESSION SET NLS_SORT = BINARY_CI;
仅当我针对Oracle 12c或18c数据库运行时,才会出现此问题。
在针对Oracle 12C R2或11g数据库运行时,它可以在有/无会话命令的情况下工作。
我已经检查了12c / 18c和12cR2的解释计划,并创建了相同的计划。
我发现,通过向查询中添加ORDER BY子句(ORDER BY TABLE_T.COL_D,可以解决此问题。
关于什么可能导致此问题的任何想法?
我知道ORDER BY解决方案有效,但是我想知道根本原因是什么,以及是否有更好的解决方案。