`

oracle select for update of ... update where current of ...

阅读更多
oracle syntax:
select for update [of [schema.]table.column[,[schema.]table.column].. ][nowait]

当查询多张表时使用for update [of [schema.]table.column[,[schema.]table.column]..]子句可以锁定指定的表(行级锁),经测试可以同时锁定多张表(行级锁),不过对应使用where current of更新数据时会有问题,这时只能用for update [of [schema.]table.column[,[schema.]table.column]..]语句锁定一张表(行级锁),然后只能更新这张表

构造测试数据:
create table mtj(name varchar2(30),sex varchar2(1),age number(3));
create table lux(name varchar2(30),sex varchar2(1),age number(3));

insert into mtj values ('mtj','M',28);
insert into mtj values ('mtj','M',28);
insert into mtj values ('mtj','M',28);
insert into mtj values ('mtj','M',28);
insert into mtj values ('mtj','M',28);
insert into mtj values ('mtj','M',28);
insert into mtj values ('mtj','M',28);

insert into lux values ('lux','M',26);
insert into lux values ('lux','M',26);
insert into lux values ('lux','M',26);
insert into lux values ('lux','M',26);
insert into lux values ('lux','M',26);
insert into lux values ('lux','M',26);
insert into lux values ('lux','M',26);
insert into lux values ('lux','M',26);


测试脚本:
declare

  cursor cur_get_person is
    select m.name name_1
      from mtj m, lux l
     where m.sex = l.sex
       for update of l.sex/* ,m.age*/;
begin

  for person in cur_get_person loop
    update lux l set l.age = 11 where current of cur_get_person;
    --update mtj m set m.age = 29 where current of cur_get_person;
  end loop;

end;


另附tom对implicit cursor效率比explicit cursor快的解释
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1205168148688
分享到:
评论

相关推荐

    Delphi7.1 Update

    not all of the features mentioned in this file are available inall editions of the product.This update resolves the following issues:IDE* Using the up/down arrow keys to navigate and select items from...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

     删除HKEY_CURRENT_USER/SOFTWARE/Microsoft/windows/CurrentVersion/Explorer/MenuOrder/Start Menu/Programs中所有以oracle 开头的键。  删除HKDY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI中除Microsoft ...

    Oracle事例

    delete from a where no in (select no from b); 14、查询从多少行到多少行的记录(可以用在web开发中的分页显示) select * from ( select rownum row_id,b.* from (select a.* from sys_oper a) b ) where row_...

    PLSQL.Developer(X64) v12.0.1.1814 主程序+ v11中文包+keygen

    It will set the current schema for all windows of this connection. The current schema will be displayed in square brackets in the Connection List: Connecting through a proxy user is now supported. ...

    PLSQL.Developer(X32) v12.0.1.1814主程序+ v11中文包+keygen

    It will set the current schema for all windows of this connection. The current schema will be displayed in square brackets in the Connection List: Connecting through a proxy user is now supported. ...

    plsqldev12.0.4.1826x32主程序+ v12中文包+keygen

    It will set the current schema for all windows of this connection. The current schema will be displayed in square brackets in the Connection List: Connecting through a proxy user is now supported. ...

    plsqldev12.0.4.1826x64主程序+ v12中文包+keygen

    It will set the current schema for all windows of this connection. The current schema will be displayed in square brackets in the Connection List: Connecting through a proxy user is now supported. ...

    oracle动态性能表

    oracle动态性能表 学习动态性能表 第一篇--v$sysstat 2007.5.23  按照OracleDocument中的描述,v$sysstat存储自数据库实例运行那刻起就开始累计全实例(instance-wide)的资源使用情况。 类似于v$sesstat,该视图...

    plsqldev12.0.6.1832x64主程序+ v12中文包+keygen

    64位版本的 PLSQL 正式版,只能运行在64位系统中,需要你安装 64 位的 Oracle11g 或 Oracle12c 客户端。 安装中文包时请注意安装路径是否为PLSQL程序的路径。 备注:新版本Ribbon启用了 Ribbon 界面,改动较大,不...

    plsqldev12.0.6.1832x32主程序+ v12中文包+keygen

    Added user interface preference "Preselect current user for object selection lists". PL/SQL Clipboard The new PL/SQL Clipboard is a dockable tool that stores the history of all SQL and PL/SQL code you...

    精髓Oralcle讲课笔记

    -- 首先,以超级管理员的身份登录oracle sqlplus sys/bjsxt as sysdba --然后,解除对scott用户的锁 alter user scott account unlock; --那么这个用户名就能使用了。 --(默认全局数据库名orcl) 1、...

    MS-DOS 5.0

    for repartitioning hard disks in Chapter 4 of the Microsoft MS-DOS Getting Started guide. 2.10 WYSE Partitions -------------------- If you have a partition created by WYSE DOS 2.11 or 3.1, you must ...

    springmybatis

    MyBatis 目录(?)[-] mybatis实战教程mybatis in action之一开发环境搭建 mybatis实战教程mybatis... select * from user where userName like #{userName} </select> 在 IUserOperation 接口中增加方法:public List...

    火车售票系统

    Class.forName("oracle.jdbc.driver.OracleDriver"); //DriverManager.registerDriver( //new oracle.jdbc.OracleDriver()); }catch (ClassNotFoundException e) {} //url 定义了数据库服务器的ip地址和服务端...

    sqlmap (懂的入)

    * Full support for MySQL, Oracle, PostgreSQL and Microsoft SQL Server database management system back-end. Besides these four DBMS, sqlmap can also identify Microsoft Access, DB2, Informix and ...

    mysql基础只是总结

    mssql 2000 Access DB2 oracle 【mysql安装】 1、官方下载mysql win32 msi 2、点击安装 3、配置 4、查看是否安装成功 通过cmd 输入netstat -a搜索3306端口是否处于listening状态 【mysql服务的启动与停止】 1...

Global site tag (gtag.js) - Google Analytics