update PRICELIST l
set L.PLEXPIRE_DATE =(
SELECT MAX(P.PLEFFECTIVE_DATE) - 1
FROM PRICELIST P
WHERE NVL(P.PLRO,'PLRO') = NVL(L.PLRO,'PLRO') AND
NVL(P.PLNS,'PLNS') = NVL(L.PLNS,'PLNS') AND
NVL(P.PLODM,'PLODM') = NVL(L.PLODM,'PLODM') AND
NVL(P.PLBRAND,'NULL') = NVL(L.PLBRAND,'NULL') AND
NVL(P.PLMRK_NAME,'NULL') = NVL(L.PLMRK_NAME,'NULL') AND
NVL(P.PLBOM_NAME,'NULL') = NVL(L.PLBOM_NAME,'NULL') AND
NVL(P.PLODD,'PLODD') = NVL(L.PLODD,'PLODD') AND
NVL(P.PLOS,'PLOS') = NVL(L.PLOS,'PLOS') AND
NVL(P.PLCPU,'PLCPU') = NVL(L.PLCPU,'PLCPU') AND
NVL(P.PLLCD,'PLLCD') = NVL(L.PLLCD,'PLLCD') AND
NVL(P.PLBEZEL,'PLBEZEL') = NVL(L.PLBEZEL,'PLBEZEL') AND
NVL(P.PLCHASSIS,'PLCHASSIS') = NVL(L.PLCHASSIS,'PLCHASSIS') AND
NVL(P.PLMS_SPECIAL,'PLMS_SPECIAL') = NVL(L.PLMS_SPECIAL,'PLMS_SPECIAL') AND
NVL(P.PLITEMNAME,'PLITEMNAME') = NVL(L.PLITEMNAME,'PLITEMNAME') AND
p.PLEXPIRE_DATE = l.PLEXPIRE_DATE
--and P.PLEFFECTIVE_DATE = l.PLEFFECTIVE_DATE
GROUP BY p.PLRO, p.PLNS, p.PLODM, p.PLBRAND, p.PLMRK_NAME, p.PLBOM_NAME, p.PLOS, p.PLCPU, p.PLLCD, p.PLODD,
p.PLBEZEL, p.PLCHASSIS, p.PLMS_SPECIAL, p.PLITEMNAME, p.PLEXPIRE_DATE
HAVING COUNT(*) > 1 and min(P.PLEFFECTIVE_DATE) = l.PLEFFECTIVE_DATE
)
where exists(
SELECT MAX(P.PLEFFECTIVE_DATE) - 1
FROM PRICELIST P
WHERE NVL(P.PLRO,'PLRO') = NVL(L.PLRO,'PLRO') AND
NVL(P.PLNS,'PLNS') = NVL(L.PLNS,'PLNS') AND
NVL(P.PLODM,'PLODM') = NVL(L.PLODM,'PLODM') AND
NVL(P.PLBRAND,'NULL') = NVL(L.PLBRAND,'NULL') AND
NVL(P.PLMRK_NAME,'NULL') = NVL(L.PLMRK_NAME,'NULL') AND
NVL(P.PLBOM_NAME,'NULL') = NVL(L.PLBOM_NAME,'NULL') AND
NVL(P.PLODD,'PLODD') = NVL(L.PLODD,'PLODD') AND
NVL(P.PLOS,'PLOS') = NVL(L.PLOS,'PLOS') AND
NVL(P.PLCPU,'PLCPU') = NVL(L.PLCPU,'PLCPU') AND
NVL(P.PLLCD,'PLLCD') = NVL(L.PLLCD,'PLLCD') AND
NVL(P.PLBEZEL,'PLBEZEL') = NVL(L.PLBEZEL,'PLBEZEL') AND
NVL(P.PLCHASSIS,'PLCHASSIS') = NVL(L.PLCHASSIS,'PLCHASSIS') AND
NVL(P.PLMS_SPECIAL,'PLMS_SPECIAL') = NVL(L.PLMS_SPECIAL,'PLMS_SPECIAL') AND
NVL(P.PLITEMNAME,'PLITEMNAME') = NVL(L.PLITEMNAME,'PLITEMNAME') AND
p.PLEXPIRE_DATE = l.PLEXPIRE_DATE
--and P.PLEFFECTIVE_DATE = l.PLEFFECTIVE_DATE
GROUP BY p.PLRO, p.PLNS, p.PLODM, p.PLBRAND, p.PLMRK_NAME, p.PLBOM_NAME, p.PLOS, p.PLCPU, p.PLLCD, p.PLODD,
p.PLBEZEL, p.PLCHASSIS, p.PLMS_SPECIAL, p.PLITEMNAME, p.PLEXPIRE_DATE
HAVING COUNT(*) > 1 and min(P.PLEFFECTIVE_DATE) = l.PLEFFECTIVE_DATE
)