Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using rowid in a delete statement

Is there any SEVERE contraindications to delete using 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);
like image 609
Revious Avatar asked Jul 19 '12 15:07

Revious


People also ask

How do you use Rowid?

ROWID s are the fastest way to access a row of data, but if you can do an operation in a single DML statement, that is faster than selecting the data first, then supplying the ROWID to the DML statement. If rows are moved, the ROWID will change. Rows can move due to maintenance operations like shrinks and table moves.

Can we use Rowid in WHERE clause?

You can use the rowid in the WHERE clause to retrieve rows based on their internal record number. This method is handy when no other unique column exists in a table. Query 4-54 uses a rowid from Query 4-53.

Can we use Rowid as primary key?

You should not use ROWID as the primary key of a table. If you delete and reinsert a row with the Import and Export utilities, for example, then its rowid may change. If you delete a row, then Oracle may reassign its rowid to a new row inserted later.

Is it safe to use Rowid to locate a record in Oracle SQL queries?

It would not be safe if you intended to use the ROWID a long period of time after you SELECT it-- for example, if you allow users to edit data locally and then synchronize with the master database some arbitrary length of time later.


1 Answers

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

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.

like image 95
a_horse_with_no_name Avatar answered Sep 21 '22 22:09

a_horse_with_no_name