How to use optimistic locking within procedure?









up vote
1
down vote

favorite
2












I implemented an optimistic lock with a trigger, how can I do it without a trigger within procedure?



I reading this post Implementic Optimistic Locking



But I do not understand how I will implement it in the procedure.



I tried this, but I don't get what I expected



SQL> CREATE OR REPLACE PACKAGE BODY account_api AS
2 PROCEDURE upd_account
3 (p_acc_id accounts.acc_id%type
4 , p_acc_name accounts.acc_name%type
5 , p_acc_amount accounts.acc_amount%type
6 , p_acc_date accounts.acc_date%type
7 , p_acc_version accounts.acc_version%type
8 )
9 IS
10 BEGIN
11 UPDATE accounts
12 set acc_name = acc_name
13 , acc_amount = acc_amount
14 , acc_date = acc_date
15 , acc_version = acc_version + 1
16 where acc_id = p_acc_id
17 and acc_version = p_acc_version;
18 if(SQL%ROWCOUNT = 0)
19 THEN
20 RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
21 END IF;
22 END;
23 end account_api;
24 /

SQL> begin
2 account_api.upd_account(1, 'user12', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.


I'm trying the code with the same timestamp and it's done now



 SQL> begin
2 account_api.upd_account(1, 'user1', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.









share|improve this question























  • I don't get what I expected": it would be useful if you specify what you do get, and how that is different from what you expected.
    – trincot
    Nov 11 at 14:18










  • I've edited the question
    – petar
    Nov 11 at 20:14










  • You are supposed to pass a number as last argument, not a date string.
    – trincot
    Nov 11 at 20:16











  • Column version is a timestamp data type, how should i forward the number?
    – petar
    Nov 11 at 20:36











  • It should not be a timestamp data type, but a plain number. You'll have to alter the data type. The idea is that it functions as an incremental version number: 1, 2, 3 ... reflecting the number of updates that record has received.
    – trincot
    Nov 11 at 20:37















up vote
1
down vote

favorite
2












I implemented an optimistic lock with a trigger, how can I do it without a trigger within procedure?



I reading this post Implementic Optimistic Locking



But I do not understand how I will implement it in the procedure.



I tried this, but I don't get what I expected



SQL> CREATE OR REPLACE PACKAGE BODY account_api AS
2 PROCEDURE upd_account
3 (p_acc_id accounts.acc_id%type
4 , p_acc_name accounts.acc_name%type
5 , p_acc_amount accounts.acc_amount%type
6 , p_acc_date accounts.acc_date%type
7 , p_acc_version accounts.acc_version%type
8 )
9 IS
10 BEGIN
11 UPDATE accounts
12 set acc_name = acc_name
13 , acc_amount = acc_amount
14 , acc_date = acc_date
15 , acc_version = acc_version + 1
16 where acc_id = p_acc_id
17 and acc_version = p_acc_version;
18 if(SQL%ROWCOUNT = 0)
19 THEN
20 RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
21 END IF;
22 END;
23 end account_api;
24 /

SQL> begin
2 account_api.upd_account(1, 'user12', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.


I'm trying the code with the same timestamp and it's done now



 SQL> begin
2 account_api.upd_account(1, 'user1', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.









share|improve this question























  • I don't get what I expected": it would be useful if you specify what you do get, and how that is different from what you expected.
    – trincot
    Nov 11 at 14:18










  • I've edited the question
    – petar
    Nov 11 at 20:14










  • You are supposed to pass a number as last argument, not a date string.
    – trincot
    Nov 11 at 20:16











  • Column version is a timestamp data type, how should i forward the number?
    – petar
    Nov 11 at 20:36











  • It should not be a timestamp data type, but a plain number. You'll have to alter the data type. The idea is that it functions as an incremental version number: 1, 2, 3 ... reflecting the number of updates that record has received.
    – trincot
    Nov 11 at 20:37













up vote
1
down vote

favorite
2









up vote
1
down vote

favorite
2






2





I implemented an optimistic lock with a trigger, how can I do it without a trigger within procedure?



I reading this post Implementic Optimistic Locking



But I do not understand how I will implement it in the procedure.



I tried this, but I don't get what I expected



SQL> CREATE OR REPLACE PACKAGE BODY account_api AS
2 PROCEDURE upd_account
3 (p_acc_id accounts.acc_id%type
4 , p_acc_name accounts.acc_name%type
5 , p_acc_amount accounts.acc_amount%type
6 , p_acc_date accounts.acc_date%type
7 , p_acc_version accounts.acc_version%type
8 )
9 IS
10 BEGIN
11 UPDATE accounts
12 set acc_name = acc_name
13 , acc_amount = acc_amount
14 , acc_date = acc_date
15 , acc_version = acc_version + 1
16 where acc_id = p_acc_id
17 and acc_version = p_acc_version;
18 if(SQL%ROWCOUNT = 0)
19 THEN
20 RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
21 END IF;
22 END;
23 end account_api;
24 /

SQL> begin
2 account_api.upd_account(1, 'user12', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.


I'm trying the code with the same timestamp and it's done now



 SQL> begin
2 account_api.upd_account(1, 'user1', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.









share|improve this question















I implemented an optimistic lock with a trigger, how can I do it without a trigger within procedure?



I reading this post Implementic Optimistic Locking



But I do not understand how I will implement it in the procedure.



I tried this, but I don't get what I expected



SQL> CREATE OR REPLACE PACKAGE BODY account_api AS
2 PROCEDURE upd_account
3 (p_acc_id accounts.acc_id%type
4 , p_acc_name accounts.acc_name%type
5 , p_acc_amount accounts.acc_amount%type
6 , p_acc_date accounts.acc_date%type
7 , p_acc_version accounts.acc_version%type
8 )
9 IS
10 BEGIN
11 UPDATE accounts
12 set acc_name = acc_name
13 , acc_amount = acc_amount
14 , acc_date = acc_date
15 , acc_version = acc_version + 1
16 where acc_id = p_acc_id
17 and acc_version = p_acc_version;
18 if(SQL%ROWCOUNT = 0)
19 THEN
20 RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
21 END IF;
22 END;
23 end account_api;
24 /

SQL> begin
2 account_api.upd_account(1, 'user12', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.


I'm trying the code with the same timestamp and it's done now



 SQL> begin
2 account_api.upd_account(1, 'user1', 1200, sysdate, '11-NOV-18 06.10.01.660948 AM');
3 end;
4 /
PL/SQL procedure successfully completed.






oracle plsql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 19:24

























asked Nov 11 at 13:59









petar

435




435











  • I don't get what I expected": it would be useful if you specify what you do get, and how that is different from what you expected.
    – trincot
    Nov 11 at 14:18










  • I've edited the question
    – petar
    Nov 11 at 20:14










  • You are supposed to pass a number as last argument, not a date string.
    – trincot
    Nov 11 at 20:16











  • Column version is a timestamp data type, how should i forward the number?
    – petar
    Nov 11 at 20:36











  • It should not be a timestamp data type, but a plain number. You'll have to alter the data type. The idea is that it functions as an incremental version number: 1, 2, 3 ... reflecting the number of updates that record has received.
    – trincot
    Nov 11 at 20:37

















  • I don't get what I expected": it would be useful if you specify what you do get, and how that is different from what you expected.
    – trincot
    Nov 11 at 14:18










  • I've edited the question
    – petar
    Nov 11 at 20:14










  • You are supposed to pass a number as last argument, not a date string.
    – trincot
    Nov 11 at 20:16











  • Column version is a timestamp data type, how should i forward the number?
    – petar
    Nov 11 at 20:36











  • It should not be a timestamp data type, but a plain number. You'll have to alter the data type. The idea is that it functions as an incremental version number: 1, 2, 3 ... reflecting the number of updates that record has received.
    – trincot
    Nov 11 at 20:37
















I don't get what I expected": it would be useful if you specify what you do get, and how that is different from what you expected.
– trincot
Nov 11 at 14:18




I don't get what I expected": it would be useful if you specify what you do get, and how that is different from what you expected.
– trincot
Nov 11 at 14:18












I've edited the question
– petar
Nov 11 at 20:14




I've edited the question
– petar
Nov 11 at 20:14












You are supposed to pass a number as last argument, not a date string.
– trincot
Nov 11 at 20:16





You are supposed to pass a number as last argument, not a date string.
– trincot
Nov 11 at 20:16













Column version is a timestamp data type, how should i forward the number?
– petar
Nov 11 at 20:36





Column version is a timestamp data type, how should i forward the number?
– petar
Nov 11 at 20:36













It should not be a timestamp data type, but a plain number. You'll have to alter the data type. The idea is that it functions as an incremental version number: 1, 2, 3 ... reflecting the number of updates that record has received.
– trincot
Nov 11 at 20:37





It should not be a timestamp data type, but a plain number. You'll have to alter the data type. The idea is that it functions as an incremental version number: 1, 2, 3 ... reflecting the number of updates that record has received.
– trincot
Nov 11 at 20:37













2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










The idea is that you would have first selected a record (through a select query) and then decide to update it. The procedure you quoted is correct. It requires that you pass it the value of acc_version as last argument. You have that value from the record you queried.



This is a kind of contract you have to follow: you need to query that acc_version and then pass it to the procedure for the update you want to make. After each update, you have to re-query what the current value of acc_version is if you still need to make more updates.



The app_version field needs to be a number (not a date). It is intended to reflect the version of the record, like version 1, 2, 3, ... which can be seen as the number of updates that have been done on that particular record.



The procedure will make the update on the condition that this value in the record was not updated in the mean time (by some other update). It uses a simple where clause for that check.



If the update does not update anything, then it means the record did not satisfy this condition any more (and was altered). In that case the exception is raised.



But if the acc_version is still as you passed it to the procedure, the update statement will indeed update the targeted record. At the same time the update statement increments acc_version. This will prevent other clients who had already queried this record before this update, to make updates. They will need to re-query the record to get the right value of acc_version, and try again.






share|improve this answer






















  • The problem is because the result is always execute, I'm gonna set up the code now
    – petar
    Nov 11 at 19:21

















up vote
0
down vote













This is what I wanted to achieve



 PROCEDURE upd_account
( p_acc_id accounts.acc_id%type
, p_acc_name accounts.acc_name%type
, p_acc_amount accounts.acc_amount%type
, p_acc_date accounts.acc_date%type
, p_version accounts.version%type
)
IS
BEGIN
UPDATE accounts
set acc_name = p_acc_name
, acc_amount = p_acc_amount
, acc_date = p_acc_date
, version = p_version + 1
where acc_id = p_acc_id
and version = p_version;
DBMS_OUTPUT.PUT_LINE ('Number of updated records: ' || TO_CHAR(SQL%ROWCOUNT));
if(SQL%ROWCOUNT = 0)
THEN
RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
END IF;
END;





share|improve this answer


















  • 1




    Warning! Here you did not put the id check in the where clause. This is NOT correct. You need to make sure the update only happens to the intended record (with a certain ID value). The way you have it now you risk to update multiple records when by coincidence they share the same version value.
    – trincot
    Nov 12 at 16:54










  • For the version I use DBMS_UTILITY.GET_TIME, but you're right, is it okay now?
    – petar
    Nov 12 at 17:06










  • Yes, it is OK now.
    – trincot
    Nov 12 at 17:11










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249487%2fhow-to-use-optimistic-locking-within-procedure%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










The idea is that you would have first selected a record (through a select query) and then decide to update it. The procedure you quoted is correct. It requires that you pass it the value of acc_version as last argument. You have that value from the record you queried.



This is a kind of contract you have to follow: you need to query that acc_version and then pass it to the procedure for the update you want to make. After each update, you have to re-query what the current value of acc_version is if you still need to make more updates.



The app_version field needs to be a number (not a date). It is intended to reflect the version of the record, like version 1, 2, 3, ... which can be seen as the number of updates that have been done on that particular record.



The procedure will make the update on the condition that this value in the record was not updated in the mean time (by some other update). It uses a simple where clause for that check.



If the update does not update anything, then it means the record did not satisfy this condition any more (and was altered). In that case the exception is raised.



But if the acc_version is still as you passed it to the procedure, the update statement will indeed update the targeted record. At the same time the update statement increments acc_version. This will prevent other clients who had already queried this record before this update, to make updates. They will need to re-query the record to get the right value of acc_version, and try again.






share|improve this answer






















  • The problem is because the result is always execute, I'm gonna set up the code now
    – petar
    Nov 11 at 19:21














up vote
2
down vote



accepted










The idea is that you would have first selected a record (through a select query) and then decide to update it. The procedure you quoted is correct. It requires that you pass it the value of acc_version as last argument. You have that value from the record you queried.



This is a kind of contract you have to follow: you need to query that acc_version and then pass it to the procedure for the update you want to make. After each update, you have to re-query what the current value of acc_version is if you still need to make more updates.



The app_version field needs to be a number (not a date). It is intended to reflect the version of the record, like version 1, 2, 3, ... which can be seen as the number of updates that have been done on that particular record.



The procedure will make the update on the condition that this value in the record was not updated in the mean time (by some other update). It uses a simple where clause for that check.



If the update does not update anything, then it means the record did not satisfy this condition any more (and was altered). In that case the exception is raised.



But if the acc_version is still as you passed it to the procedure, the update statement will indeed update the targeted record. At the same time the update statement increments acc_version. This will prevent other clients who had already queried this record before this update, to make updates. They will need to re-query the record to get the right value of acc_version, and try again.






share|improve this answer






















  • The problem is because the result is always execute, I'm gonna set up the code now
    – petar
    Nov 11 at 19:21












up vote
2
down vote



accepted







up vote
2
down vote



accepted






The idea is that you would have first selected a record (through a select query) and then decide to update it. The procedure you quoted is correct. It requires that you pass it the value of acc_version as last argument. You have that value from the record you queried.



This is a kind of contract you have to follow: you need to query that acc_version and then pass it to the procedure for the update you want to make. After each update, you have to re-query what the current value of acc_version is if you still need to make more updates.



The app_version field needs to be a number (not a date). It is intended to reflect the version of the record, like version 1, 2, 3, ... which can be seen as the number of updates that have been done on that particular record.



The procedure will make the update on the condition that this value in the record was not updated in the mean time (by some other update). It uses a simple where clause for that check.



If the update does not update anything, then it means the record did not satisfy this condition any more (and was altered). In that case the exception is raised.



But if the acc_version is still as you passed it to the procedure, the update statement will indeed update the targeted record. At the same time the update statement increments acc_version. This will prevent other clients who had already queried this record before this update, to make updates. They will need to re-query the record to get the right value of acc_version, and try again.






share|improve this answer














The idea is that you would have first selected a record (through a select query) and then decide to update it. The procedure you quoted is correct. It requires that you pass it the value of acc_version as last argument. You have that value from the record you queried.



This is a kind of contract you have to follow: you need to query that acc_version and then pass it to the procedure for the update you want to make. After each update, you have to re-query what the current value of acc_version is if you still need to make more updates.



The app_version field needs to be a number (not a date). It is intended to reflect the version of the record, like version 1, 2, 3, ... which can be seen as the number of updates that have been done on that particular record.



The procedure will make the update on the condition that this value in the record was not updated in the mean time (by some other update). It uses a simple where clause for that check.



If the update does not update anything, then it means the record did not satisfy this condition any more (and was altered). In that case the exception is raised.



But if the acc_version is still as you passed it to the procedure, the update statement will indeed update the targeted record. At the same time the update statement increments acc_version. This will prevent other clients who had already queried this record before this update, to make updates. They will need to re-query the record to get the right value of acc_version, and try again.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 21:28

























answered Nov 11 at 14:11









trincot

114k1477109




114k1477109











  • The problem is because the result is always execute, I'm gonna set up the code now
    – petar
    Nov 11 at 19:21
















  • The problem is because the result is always execute, I'm gonna set up the code now
    – petar
    Nov 11 at 19:21















The problem is because the result is always execute, I'm gonna set up the code now
– petar
Nov 11 at 19:21




The problem is because the result is always execute, I'm gonna set up the code now
– petar
Nov 11 at 19:21












up vote
0
down vote













This is what I wanted to achieve



 PROCEDURE upd_account
( p_acc_id accounts.acc_id%type
, p_acc_name accounts.acc_name%type
, p_acc_amount accounts.acc_amount%type
, p_acc_date accounts.acc_date%type
, p_version accounts.version%type
)
IS
BEGIN
UPDATE accounts
set acc_name = p_acc_name
, acc_amount = p_acc_amount
, acc_date = p_acc_date
, version = p_version + 1
where acc_id = p_acc_id
and version = p_version;
DBMS_OUTPUT.PUT_LINE ('Number of updated records: ' || TO_CHAR(SQL%ROWCOUNT));
if(SQL%ROWCOUNT = 0)
THEN
RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
END IF;
END;





share|improve this answer


















  • 1




    Warning! Here you did not put the id check in the where clause. This is NOT correct. You need to make sure the update only happens to the intended record (with a certain ID value). The way you have it now you risk to update multiple records when by coincidence they share the same version value.
    – trincot
    Nov 12 at 16:54










  • For the version I use DBMS_UTILITY.GET_TIME, but you're right, is it okay now?
    – petar
    Nov 12 at 17:06










  • Yes, it is OK now.
    – trincot
    Nov 12 at 17:11














up vote
0
down vote













This is what I wanted to achieve



 PROCEDURE upd_account
( p_acc_id accounts.acc_id%type
, p_acc_name accounts.acc_name%type
, p_acc_amount accounts.acc_amount%type
, p_acc_date accounts.acc_date%type
, p_version accounts.version%type
)
IS
BEGIN
UPDATE accounts
set acc_name = p_acc_name
, acc_amount = p_acc_amount
, acc_date = p_acc_date
, version = p_version + 1
where acc_id = p_acc_id
and version = p_version;
DBMS_OUTPUT.PUT_LINE ('Number of updated records: ' || TO_CHAR(SQL%ROWCOUNT));
if(SQL%ROWCOUNT = 0)
THEN
RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
END IF;
END;





share|improve this answer


















  • 1




    Warning! Here you did not put the id check in the where clause. This is NOT correct. You need to make sure the update only happens to the intended record (with a certain ID value). The way you have it now you risk to update multiple records when by coincidence they share the same version value.
    – trincot
    Nov 12 at 16:54










  • For the version I use DBMS_UTILITY.GET_TIME, but you're right, is it okay now?
    – petar
    Nov 12 at 17:06










  • Yes, it is OK now.
    – trincot
    Nov 12 at 17:11












up vote
0
down vote










up vote
0
down vote









This is what I wanted to achieve



 PROCEDURE upd_account
( p_acc_id accounts.acc_id%type
, p_acc_name accounts.acc_name%type
, p_acc_amount accounts.acc_amount%type
, p_acc_date accounts.acc_date%type
, p_version accounts.version%type
)
IS
BEGIN
UPDATE accounts
set acc_name = p_acc_name
, acc_amount = p_acc_amount
, acc_date = p_acc_date
, version = p_version + 1
where acc_id = p_acc_id
and version = p_version;
DBMS_OUTPUT.PUT_LINE ('Number of updated records: ' || TO_CHAR(SQL%ROWCOUNT));
if(SQL%ROWCOUNT = 0)
THEN
RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
END IF;
END;





share|improve this answer














This is what I wanted to achieve



 PROCEDURE upd_account
( p_acc_id accounts.acc_id%type
, p_acc_name accounts.acc_name%type
, p_acc_amount accounts.acc_amount%type
, p_acc_date accounts.acc_date%type
, p_version accounts.version%type
)
IS
BEGIN
UPDATE accounts
set acc_name = p_acc_name
, acc_amount = p_acc_amount
, acc_date = p_acc_date
, version = p_version + 1
where acc_id = p_acc_id
and version = p_version;
DBMS_OUTPUT.PUT_LINE ('Number of updated records: ' || TO_CHAR(SQL%ROWCOUNT));
if(SQL%ROWCOUNT = 0)
THEN
RAISE_APPLICATION_ERROR( -20001, 'Oops, the row has changed since you read it.' );
END IF;
END;






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 17:07

























answered Nov 12 at 16:35









petar

435




435







  • 1




    Warning! Here you did not put the id check in the where clause. This is NOT correct. You need to make sure the update only happens to the intended record (with a certain ID value). The way you have it now you risk to update multiple records when by coincidence they share the same version value.
    – trincot
    Nov 12 at 16:54










  • For the version I use DBMS_UTILITY.GET_TIME, but you're right, is it okay now?
    – petar
    Nov 12 at 17:06










  • Yes, it is OK now.
    – trincot
    Nov 12 at 17:11












  • 1




    Warning! Here you did not put the id check in the where clause. This is NOT correct. You need to make sure the update only happens to the intended record (with a certain ID value). The way you have it now you risk to update multiple records when by coincidence they share the same version value.
    – trincot
    Nov 12 at 16:54










  • For the version I use DBMS_UTILITY.GET_TIME, but you're right, is it okay now?
    – petar
    Nov 12 at 17:06










  • Yes, it is OK now.
    – trincot
    Nov 12 at 17:11







1




1




Warning! Here you did not put the id check in the where clause. This is NOT correct. You need to make sure the update only happens to the intended record (with a certain ID value). The way you have it now you risk to update multiple records when by coincidence they share the same version value.
– trincot
Nov 12 at 16:54




Warning! Here you did not put the id check in the where clause. This is NOT correct. You need to make sure the update only happens to the intended record (with a certain ID value). The way you have it now you risk to update multiple records when by coincidence they share the same version value.
– trincot
Nov 12 at 16:54












For the version I use DBMS_UTILITY.GET_TIME, but you're right, is it okay now?
– petar
Nov 12 at 17:06




For the version I use DBMS_UTILITY.GET_TIME, but you're right, is it okay now?
– petar
Nov 12 at 17:06












Yes, it is OK now.
– trincot
Nov 12 at 17:11




Yes, it is OK now.
– trincot
Nov 12 at 17:11

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249487%2fhow-to-use-optimistic-locking-within-procedure%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto