Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 11th, 2006, 11:24 AM
bhaarat bhaarat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 192 bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 17 h 6 m 45 sec
Reputation Power: 5
Locking database for Update

Hello

I am wondering if there is a builtin method by which the selected record can be locked for update?

In my case the user can search for a record thru search page, this takes him to listing page where listing of records matching the search are showed. User can then click any of the records in the listing page to update the record. However the problem is that in the database there are is no column that is unique (something like ID column). So once the user clicks the record on the listing page, this takes him to update page. At update page to perform the query i dont have anything to put in the WHERE clause of the UPDATE query. since there is no unique column.

so I was wondering if there is any way to Lock the record in oracle or hold the record that the user selected and store it? using sql statements or builtin class method?

Thanks

Reply With Quote
  #2  
Old July 11th, 2006, 12:10 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 6 h 19 m 24 sec
Reputation Power: 48
Code:
LOCK TABLE MYTABLE
IN ROW EXCLUSIVE MODE;


Use with caution please...

Oracle is VERY big on read consistency.

Once you execute a select, you are guaranteed to get all of the resultset rows from the table, EXACTLY as they were at the START of the select. You will not see data updated by another operation that completed while you are in the select.
(ie, you are reading a cursor).

Oracle is not Access.

Last edited by jim mcnamara : July 11th, 2006 at 12:14 PM.

Reply With Quote
  #4  
Old July 11th, 2006, 03:20 PM
bhaarat bhaarat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 192 bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 17 h 6 m 45 sec
Reputation Power: 5
Quote:
Originally Posted by jim mcnamara
Code:
LOCK TABLE MYTABLE
IN ROW EXCLUSIVE MODE;


Use with caution please...

Oracle is VERY big on read consistency.

Once you execute a select, you are guaranteed to get all of the resultset rows from the table, EXACTLY as they were at the START of the select. You will not see data updated by another operation that completed while you are in the select.
(ie, you are reading a cursor).

Oracle is not Access.


Thanks a lot!
but im not too sure what that statement actually does? could you please explain it when u get time?

Will that work for my purpose? of kind of holding the record that the user clicked on? From the listings page the user clicks one of the records and this takes the user to the update page where all the fields are populated with information thats stored in the database for the particular field that the user clicked on. so when the user clicks update....how do i know what to put in the WHERE clause of the UPDATE query since there is no unique ID column in the database. Sorry if im being naive to somethint thats obvious from your answer

Reply With Quote
  #5  
Old July 12th, 2006, 07:13 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 6 h 19 m 24 sec
Reputation Power: 48
In form-based PL/SQL select .. for update is what you want to use, pabloj shows you just what you need.

The LOCK statement is meant largely for a SQL script

Reply With Quote
  #6  
Old July 12th, 2006, 07:25 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,040 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 6 Days 12 h 33 m 44 sec
Reputation Power: 281
Quote:
Originally Posted by jim mcnamara
pabloj shows you just what you need.
I know my chickens (as we use to say) but maybe I'm getting too minimalistic (or RTFM prone )
Regards

Reply With Quote
  #7  
Old July 12th, 2006, 08:14 AM
bhaarat bhaarat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 192 bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level)bhaarat User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 17 h 6 m 45 sec
Reputation Power: 5
Quote:
Originally Posted by pabloj
I know my chickens (as we use to say) but maybe I'm getting too minimalistic (or RTFM prone )
Regards

Sorry i didnt reply to ur post specifically but i did RTFM Maybe you can explain me better how select for update will work.

What I am saying is that my database in which i am doing an update does not have any UNIQUE columns. So when i write the UPDATE QUERY i dont have nethin to write in the where clause.

So according to the manual, for example:
-------BEGIN TRANSACTION-------
select color from cust where
id=500 for update;
----------------------------------
From what i understand after reading those examples is that when we perform select...for update, all it does is makes another session wait to run select query on the same record. right? so how will that help me? lets say on the listing page there are 3 records, AA BB CC. User clicks the first record, AA, this takes him to the update page where all the fields are populated from the info that was in DB. now when the user clicks update after editing the fields on the page....how would i perform the update query when there is no unique column?

The issue is that the select ...for update query also must have a where clause.

i need some way of knowing which record did the user click on from the listings page...? im so lost!

Reply With Quote
  #8  
Old July 12th, 2006, 08:29 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 8,040 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 6 Days 12 h 33 m 44 sec
Reputation Power: 281
Quote:
Originally Posted by bhaarat
lets say on the listing page there are 3 records, AA BB CC. User clicks the first record, AA, this takes him to the update page where all the fields are populated from the info that was in DB.

Fine, you'll start a transaction, then use a "select ... where col = 'AA' for update" (thus locking the record the users choose) to populate the form
Quote:
Originally Posted by bhaarat
now when the user clicks update after editing the fields on the page....how would i perform the update query when there is no unique column?
How could you decide which record present to the user? This tells me that there is something that makes you choose that record (otherwise use rowid ...)
Quote:
Originally Posted by bhaarat
The issue is that the select ...for update query also must have a where clause.
Not really, but a table without PK or Unique constraint is badly designed and flawed anyway
Quote:
i need some way of knowing which record did the user click on from the listings page...? im so lost!
In desperate cases you can use the rowid but I'd clean up my data and correct the table structure adding a PK or an unique constraint before going to that extreme.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Locking database for Update


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT