title: How to use optimistic locking within procedure?
body: <p>I implemented an optimistic lock with a trigger, how can I do it without a trigger within procedure?</p>
  
  <p>I reading this post <a href="https://stackoverflow.com/questions/41006941/implementing-optimistic-locking-in-oracle/41008087#41008087">Implementic Optimistic Locking</a></p>
  
  <p>But I do not understand how I will implement it in the procedure.</p>
  
  <p>I tried this, but I don't get what I expected</p>
  
  <pre><code>SQL&gt; 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&gt; 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.
  </code></pre>
  
  <p>I'm trying the code with the same timestamp and it's done now</p>
  
  <pre><code>   SQL&gt; 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.
  </code></pre>