I would like to ask you how I can lock a record and not the complete table. I assigned a predefined number to an invoice, but I got duplicate numbers if two people at the same time want that invoice. I read that I could use the for update at the end of SQL statement but I am not sure:
Select xx from yy where zz=zx for update
The SELECT FOR UPDATE will get data from a table, and then lock the rows that are returned so that you can update them. Once you commit or rollback, your lock is released. For instance:
SELECT empno FROM emp WHERE emp_name='John Q' FOR UPDATE;The row(s) returned is now locked by your session. Other sessions will be able to see this row, but not update it. You will be able to modify this row and then commit or rollback to release the lock.
For More Information
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.