oracle 在删除语句中使用 rowid

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11564459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:58:55  来源:igfitidea点击:

Using rowid in a delete statement

oraclesql-delete

提问by Revious

Is there any SEVERE contraindications to delete using rowid?

使用 rowid 删除是否有任何严重的禁忌症?

DELETE FROM NETATEMP.SFAC_TESTATA_CASISTICHE
      WHERE ROWID IN (  SELECT MIN (ROWID)
                          FROM NETATEMP.SFAC_TESTATA_CASISTICHE
                      GROUP BY ID_CASO,
                               DESCRIZIONE_TECNICA,
                               DESCRIZIONE_ANALISI,
                               PDF,
                               SCARTI,
                               DATA_INIZIO_ANALISI,
                               DATA_FINE_ANALISI,
                               DATA_INSTRADAMENTO,
                               DATA_RISOLUZIONE,
                               STRINGA_RICERCA,
                               SETTIMANA,
                               DATA_INIZIO_SETT,
                               DATA_FINE_SETT,
                               FATTURAZIONE,
                               IN_ELABORAZIONE
                        HAVING COUNT (1) > 1);

回答by a_horse_with_no_name

If you assume that min(rowid)returns the "earliest" row, then yes, you have a problem (because it won't)

如果您假设min(rowid)返回“最早”行,那么是的,您有问题(因为它不会)

If you use min(rowid)only to get one of the duplicates (and you don't care which), then no, there is nothing wrong with that statement.

如果您min(rowid)仅用于获取其中一个副本(并且您不在乎哪个),那么不,该语句没有任何问题。

回答by tbone

A few things to be aware of. It seems you are depending on the rowid to give you the earliest row for your particular grouping (select min(rowid) ...). This won't always be true. The only way to guarantee you are deleting the earliest record is to use some column (like timestamp) that you can order by. Tom Kyte explains thisbetter than I could.

需要注意的几件事。似乎您依赖 rowid 为您的特定分组提供最早的行(选择 min(rowid) ...)。这并不总是正确的。保证您删除最早记录的唯一方法是使用您可以订购的某些列(如时间戳)。 Tom Kyte比我更好地解释了这一点。

A rowid implies NOTHING other than the location of the row physically. It does not imply age, order of insertion, or anything like that.

rowid 除了物理上的行位置外,没有任何其他含义。它并不意味着年龄、插入顺序或类似的东西。

Also, depending on the size of the table, you will generate a lot of redo/undo, and it may be beneficial in large tables to use pl/sql to delete in chunks and commit every x rows.

另外,根据表的大小,你会产生大量的redo/undo,在大表中使用pl/sql分块删除并每x行提交可能会有好处。

Just my thoughts

只是我的想法