I have an application in C# that uses an Oracle database.
I need a query to fetch the unlocked row from a table in oracle database.
How can I select all unlocked rows?
Is there any ‘translator’ out there that can translate this T-SQL (MS SQL Server) query to Oracle dialect?
SELECT TOP 1 * FROM TableXY WITH(UPDLOCK, READPAST);
I’m a little bit disappointed with Oracle lacking such a feature. They want to make me use AQ or what?
Oracle does have this feature, specifically the SKIP LOCKED portion of the SELECT statement. To quote:
The documentation goes on to say it’s designed for use in multi-consumer queues but this does not mean that you have to use it in this environment. Though the documentation says this there is a large caveat. You can’t ask for the next N unlocked rows – only the next N rows, of which the unlocked ones will be returned.
Note that if the table you’re selecting from is locked in exclusive mode, i.e. you’ve already instructed the database not to let any other session lock the table you will not get any rows returned until the exclusive lock is released.