select for update 的意思

SELECT  FOR  UPDATE  光标
为了对正在处理(查询) 的行不被另外的用户改动,oracle 提供一个 FOR UPDATE 子句来对所选择的行进行锁住.

--写订票的存储过程
    create or replace procedure get_ticket(no number)
    as
     sl number;
     no_ticket exception;
    begin
    --<1>查出余数(加锁)
      select remain_sl into sl
       from ticket where train_no = no
       for update;
    --<2>判断余数的数量
      if sl > 0 then
        --修改
         update ticket set remain_sl
            =remain_sl - 1
         where train_no = no;
         dbms_output.put_line('订票成功');
      else
        raise no_ticket;
      end if;
    --<3>
       commit;   --必须的 
    exception
       when no_ticket then
         raise_application_error(-20001,'票已经售完了');
         rollback;  --很关键的,解除锁
    end;
原文地址:https://www.cnblogs.com/pan11jing/p/1545367.html