Home » SQL & PL/SQL » SQL & PL/SQL » Dirty read issues
Dirty read issues [message #637366] Fri, 15 May 2015 10:41 Go to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
I have a table and two different jobs are populating that table at different times. Sometimes it happens that both the jobs start together and its like one job checks for a security and if it doesnot find the security ,it creates a record in the table. Now while its about to commit,job 2 also finds that there is no security(dirty read on table)and he also creates a records. We have security_id as primary key and which is generated randomly while a record is created to the table. How can i avoid this situation. I need only one record to the table. So after these transaction the situation becomes like 2 similar records in table with 2 different security_id. Kindly suggest what can be done to avoid this.
Re: Dirty read issues [message #637367 is a reply to message #637366] Fri, 15 May 2015 11:35 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.oracle.com/technetwork/issue-archive/2010/10-jan/o65asktom-082389.html
Oracle does not allow "Dirty Read" (read uncommitted) to occur.
Above is not a database problem; but an application problem.
So change the application to obtain the behavior you desire.
Re: Dirty read issues [message #637368 is a reply to message #637366] Fri, 15 May 2015 11:49 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
I need only one record to the table.


Does this mean there can be only one row in the table at each point in the time?

Re: Dirty read issues [message #637382 is a reply to message #637366] Sat, 16 May 2015 03:36 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Quote:
one job checks for a security and if it doesnot find the security ,it creates a record in the table.
This check must be being made on a natural key. So declare this as unique, and the second insert will then fail. Just because you have a surrogate primary key is no reason not to have natural keys as well.

And, by the way, the behaviour you are describing is "read committed", not "dirty read".

[Updated on: Sat, 16 May 2015 03:38]

Report message to a moderator

Re: Dirty read issues [message #637407 is a reply to message #637382] Sun, 17 May 2015 05:30 Go to previous messageGo to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
Thanks John for correcting me. Yeah that's Read committed. Also,i agree that if i create a unique constraint 2nd insert will fail. But i dont want the system to stop thorwing any issue. I am looking to create some kind of dependency on the jobs to avoid such situtation.
Re: Dirty read issues [message #637409 is a reply to message #637407] Sun, 17 May 2015 05:55 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

So you are searching for an application solution which is not an Oracle one.
Search for "pessimist/optimist locking".
Anyway you have to change the application.

[Updated on: Mon, 18 May 2015 03:34]

Report message to a moderator

Re: Dirty read issues [message #637454 is a reply to message #637409] Mon, 18 May 2015 03:33 Go to previous messageGo to next message
raj_te
Messages: 46
Registered: August 2013
Location: INDIA
Member
Thanks Mike for the suggestion.
Re: Dirty read issues [message #637516 is a reply to message #637454] Tue, 19 May 2015 08:04 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
If you want to you can always use the LOCK TABLE command while you make your primary key. Any commit or rollback will release the lock.
Previous Topic: what is the difference between "generated always as" and "as" at the time of creating virtual column
Next Topic: Subquery with multiple rows
Goto Forum:
  


Current Time: Fri Apr 26 02:20:36 CDT 2024