Oracle中的两个删除语句以删除重复项
我们有一张超过55k行的表,重复了一个识别名称。该名称可能会有所不同,每个名称的重复项数量可能会有所不同。因此,我将这两个脚本应用于练习中,从表中删除重复记录。有区别吗?脚本有任何问题吗?输出似乎是一样的。
DELETE FROM RDSUSER.A_JOB
WHERE ROWID IN (SELECT ROWID
FROM (SELECT ROWID
, ROW_NUMBER() OVER(PARTITION BY JOB_NAME ORDER BY JOB_NAME) DUP
FROM RDSUSER.A_JOB)
WHERE DUP > 1);
DELETE FROM RDSUSER.A_JOB JOB
WHERE ROWID > (SELECT MIN(ROWID)
FROM A_JOB
WHERE JOB.JOB_NAME = A_JOB.JOB_NAME);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
Will
条款是非确定性的,分区中的行将有效地随机编号,并且不能保证将分区中的行保留/删除。
job_name
通过job_name 订购 ,并且由于分区中的所有job_name
将与这意味着,如果您运行查询,然后
回滚
再次运行查询,则第二次已删除的行可能会不同(例如,如果您在并行系统上运行查询)。将始终保留每个 job_name 的最小
rowID
,并且要保留/删除的行选择将是确定性的。这意味着,如果您运行查询,然后
回滚
更改并第二次运行删除,则将删除一组相同的行。如果要查询相同的函数,则可以使用:
随机排序的一个示例是:
后面:
表可以包含:
,但如果您
回滚
,然后:然后输出可能是:
db<>> fiddle
Yes.
Will
PARTITION BY JOB_NAME
and thenORDER BY JOB_NAME
and since all theJOB_NAME
within the partition are going to be identical then theORDER BY
clause is non-deterministic and the rows within the partition will be given an effectively random numbering for the rows and it is not guaranteed which rows in the partition will be kept/deleted.This means that if you run the query and then
ROLLBACK
and run the query again then the set of deleted rows may be different the second time (for example, if you run the query on a parallel system).Will always keep the minimum
ROWID
for eachJOB_NAME
and the selection of rows to be kept/deleted will be deterministic.This means that if you run the query and then
ROLLBACK
the change and run the delete a second time then an identical set of rows will be deleted.If you want the queries to function identically then you can use:
An example of the random ordering is:
Then after:
The table may contain:
But if you
ROLLBACK
and then:Then the output may be:
db<>fiddle here