|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
Look at select ... for update
__________________
My blog Tutorials about OSS databases, DBMonster ... Contribute to OSS Development, fill bug reports! Developer Shed eSupport Commented my.ini/my.cnf (ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins Random data (with a bias) |
|
#4
|
|||
|
|||
|
Quote:
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 |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
Quote:
)Regards |
|
#7
|
|||
|
|||
|
Quote:
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! |
|
#8
|
||||||
|
||||||
|
Quote:
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:
Quote:
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Locking database for Update |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|