Oracle operator and TSQL NO LOCK

select max(Key) from MyTable with(nolock) 

I have this T-SQL statement, but you need to use one statement for both SQL Server and Oracle, of course, "with (nolock)" is not recognized by Oracle. Is there a way for this statement to be executed on both databases. Both Oracle ignore "with (nolock)" or only Sqlserver, using this part of the instruction or method or encoded, as with understanding.

The reason I use No lock is because multiple users are accessing the same table and I need to find the maximum value during transactions.

Oracle does things differently, so I don't have to worry about locking tables.

+4
source share
1 answer

Your requests do different things. What is the semantics of the query, which should be? Should it return max(Key) , including the effect of idle transactions, as your version of SQL Server indicates? If so

 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; select max(Key) from MyTable; 

It is the same semantics. The syntax should work fine on both AFAIKs.

If you need the last highlighted max(Key) instead, you will need to modify the SQL Server database to use a secure snapshot lock by default, so it behaves similarly to Oracle. Or, alternatively, you could achieve similar semantics with the ROWLOCK,READPAST , but then again you need two different queries.

+5
source

Source: https://habr.com/ru/post/1389056/


All Articles