【问题标题】:running delete command to remove duplicate in oracle with cte is giving ora-00928 error使用 cte 运行删除命令以删除 oracle 中的重复项给出 ora-00928 错误
【发布时间】:2021-06-29 20:00:46
【问题描述】:

我正在运行以下查询以从我的表中删除重复项,但它给出了以下错误:

with cte as (select  name,address,designation, row_number() over(partition by name,address,designation order by name) rn from emp)
delete from cte where rn <>1;
select * from emp;

错误:ORA-00928:缺少 SELECT 关键字

如何解决这个问题?

【问题讨论】:

标签: sql oracle duplicates common-table-expression


【解决方案1】:

您不能从 CTE 或内联视图中删除。

我经常使用的:

delete emp
where  rowid in
       ( select lag(rowid) over (partition by name,address,designation order by name)
         from   emp );

Removing duplicate rows from table in Oracle 上有很多更复杂的方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-18
    • 2016-02-21
    • 2012-10-14
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 2021-07-16
    • 2020-04-22
    相关资源
    最近更新 更多