Search code examples
oracle-databasesql-deletedml

Oracle delete skip locked


Does oracle allows to delete rows from a table with some condition and skip the locked once

DELETE from t 
 WHERE t.id IN (SELECT id 
                  FROM t 
                 WHERE id in ('1','2') 
                   FOR UPDATE SKIP LOCKED )

For example id 2 is locked by other session and deletion script should skip that row

The query above always fails with error

ORA-00907: missing right parenthesis

Version : Oracle 11G XE


Solution

  • Following up on Jeffrey's answer, I believe this clause was intended for use in PL/SQL blocks. So you could try this, for example:

    begin
      for r in (select rowid as rid from t for update skip locked)
      loop
        delete from t where rowid = r.rid;
      end loop;
    end;
    /