我有一些 SQL,要添加这个问题中的所有语句太多了,我正在努力改进以消除系统减速。
在部分 PL/SQL 中有一个AND Exists子句,其中包含一个AND Not Exists子句。
这两个子句都包含Case语句。在 case 语句的End部分之后,有一个IS NOT NULL或IS NULL语句。使用 PL/SQL 多年,这是我第一次看到这种语法,我坦率地承认不理解它。整个AND Exists子句如下所示,非常感谢您的帮助。
AND EXISTS (
SELECT Distinct PROJECTID
From Milestone_History MH,
Project_Milestone PM
Where MH.MilestoneId = PM.ID
AND MH.Projectid = PR.ID
AND ((UPPER(PM.Description) = 'FINAL BUILD INVOICE INSTRUCTIONS ISSUED') OR
(UPPER(PM.Description) = 'FEASIBILITY STUDY REQUIRED') OR
(UPPER(PM.Description) = 'PROJECT COMPLETE'))
AND (case when UPPER(PM.Description) = 'FEASIBILITY STUDY REQUIRED' then
Actual
End IS NOT NULL
AND
case
when UPPER(PM.Description) = 'PROJECT COMPLETE' then
MH.Actual
end IS NULL)
AND NOT EXISTS
(SELECT Distinct MH2.ProjectID
From Milestone_History MH2, Project_Milestone PM2
Where MH2.MilestoneId = PM2.ID
And MH2.ProjectID = MH.ProjectID
AND case
when UPPER(PM2.Description) = 'PROJECT COMPLETE' then -
MH2.Actual
end IS NOT NULL))