在执行此操作时,将引发抛出错误“ Missing Select Statement”。我正在尝试按照以下方案删除重复的记录。
With CTE as (
select exrt, currencyfrom, currencyto, ratetype, year,
period, validfrom, factor, rate,
ROW_NUMBER() OVER (
PARTITION BY exrt, currencyfrom, currencyto,
ratetype, year, period, validfrom, factor, rate
ORDER BY exrt, currencyfrom, currencyto, ratetype, year, period,
validfrom,factor,rate
) row_num
from udt_dp_exchangerate
where validfrom = TO_DATE('2019-SEP-28', 'YYYY-MON-DD') and period = '9'
)
delete from cte where row_num > 1
答案 0 :(得分:0)
您应该尝试使用以下查询而不是CTE-
DELETE FROM udt_dp_exchangerate UDE1
WHERE ROWID > (SELECT MIN(ROWID)
FROM udt_dp_exchangerate UDE2
WHERE UDE1.exrt = UDE2.exrt
AND UDE1.currency = UDE2.currency
AND UDE1.currencyto = UDE2.currencyto
AND UDE1.ratetype = UDE2.ratetype
AND UDE1.year = UDE2.year
AND UDE1.period = UDE2.period
AND UDE1.validfrom = UDE2.validfrom
AND UDE1.factor = UDE2.factor
AND UDE1.rate = UDE2.rate)
AND UDE1.validfrom = TO_DATE('2019-SEP-28', 'YYYY-MON-DD')
AND UDE1.period='9';
答案 1 :(得分:0)
在oracle中,delete语句不允许CTE。
您需要尝试以下查询:
Delete from udt_dp_exchangerate
Where (rowid, 1) not in
(select rowid,
ROW_NUMBER() OVER (PARTITION BY
exrt,currencyfrom,currencyto,ratetype,year,period,validfrom,factor,rate
ORDER BY
exrt,currencyfrom,currencyto,ratetype,year,period,validfrom,factor,rate
) row_num
from udt_dp_exchangerate
where validfrom = TO_DATE('2019-SEP-28', 'YYYY-MON-DD')
and period='9')
干杯!