plsql - PL/SQL Case Statement - IS NULL -
i have sql, far add of statement in question, trying improve in order drive out system slowdowns.
in part of pl/sql there and exists clause contains and not exists clause.
both of these clauses contain case statements. after end part of case statement, there either is not null or is null statement. having used pl/sql years first time have seen syntax , freely admit not understanding it. whole of and exists clause displayed below, , appreciated.
and exists ( select distinct projectid milestone_history mh, project_milestone pm mh.milestoneid = pm.id , mh.projectid = pr.id , ((upper(pm.description) = 'final build invoice instructions issued') or (upper(pm.description) = 'feasibility study required') or (upper(pm.description) = 'project complete')) , (case when upper(pm.description) = 'feasibility study required' actual end not null , case when upper(pm.description) = 'project complete' mh.actual end null) , not exists (select distinct mh2.projectid milestone_history mh2, project_milestone pm2 mh2.milestoneid = pm2.id , mh2.projectid = mh.projectid , case when upper(pm2.description) = 'project complete' - mh2.actual end not null))
think of case...end
single expression. can use parentheses better understanding:
(case when upper(pm.description) = 'feasibility study required' actual end) not null
this particular expression not null
if , if case
finds match , actual
not null.
this rewritten as:
(upper(pm.description) = 'feasibility study required' , actual not null)
the following statement rewritten as:
(upper(pm.description) != 'project complete' or pm.description null or actual null)
the 2 statements overlapping: descrition
can have 1 value. when merge them there not left:
(select distinct projectid milestone_history mh, project_milestone pm mh.milestoneid = pm.id , mh.projectid = pr.id , upper(pm.description) = 'feasibility study required' , actual not null , not exists (select distinct mh2.projectid milestone_history mh2, project_milestone pm2 mh2.milestoneid = pm2.id , mh2.projectid = mh.projectid , pm2.description = 'project complete' , mh2.actual not null) )
i think it's bit misleading use case
when there single case.
either author misinformed behaviour of case
or remnant code has been updated along way without being cleaned.
Comments
Post a Comment