sql – 使用SELECT锁定Oracle … FOR UPDATE OF

前端之家收集整理的这篇文章主要介绍了sql – 使用SELECT锁定Oracle … FOR UPDATE OF前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从桌子FOO和BAR中选择.我想锁定正在返回的FOO的记录,但我不想锁定BAR的记录.
cursor c_foobar is 
select foo.*,bar.* from
foo,bar
where foo.id = bar.foo_id
for update of <what should I put here?>

好像我需要指定单独的列,但我希望锁定整个foo记录.例如我希望我可以这样做:

cursor c_foobar is
select foo.*,bar
where foo.id = bar.foo_id
for update of foo

我是否必须在更新部分中枚举foo的每一列以便将它们全部锁定?或者我可以随意选择foo中的任何列,即使那些不是它的主键,它会锁定整个记录吗?

解决方法

the 10G PL/SQL documentation开始:

When querying multiple tables,you can
use the FOR UPDATE clause to confine
row locking to particular tables. Rows
in a table are locked only if the FOR
UPDATE OF clause refers to a column
in that table. For example,the
following query locks rows in the
employees table but not in the
departments table:

@H_403_25@
DECLARE
  CURSOR c1 IS SELECT last_name,department_name FROM employees,departments
    WHERE employees.department_id = departments.department_id 
          AND job_id = 'SA_MAN'
      FOR UPDATE OF salary;
原文链接:https://www.f2er.com/mssql/84339.html

猜你在找的MsSQL相关文章