ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [pl sql] where current of

[pl sql] where current of

原创 Linux操作系统 作者:yellowlee 时间:2009-01-07 11:15:26 0 删除 编辑

使用select for update 的时候的几个问题

1,使用显示静态游标

eg:

create table tb_test_1 (id number,
name varchar2(20));

insert into tb_test_1 (id, name) values (1, 'name');

declare
  my_test test.tb_test_1%rowtype;
  cursor cs is
    select * from tb_test_1 for update;
begin

  for css in cs loop
    my_test.id   := css.id;
    my_test.name := css.name || 's';
    update tb_test_1 a
       set a.id = my_test.id, a.name = my_test.name
     where current of cs;
  end loop;
  commit;

end;

 

若:

declare
  my_test test.tb_test_1%rowtype;
  type cs is ref cursor;
  css cs;
begin

  open css for
  select * from tb_test_1 for update;
 
  loop
 
  fetch css into my_test;
  exit when css%notfound;
    update tb_test_1 a
       set a.id = my_test.id, a.name = my_test.name||'s'
     where current of css;
  end loop;
  commit;

end;

则ora-06550

 

2,注意loop内不能commit

eg:

insert into tb_test_1 (id, name) values (2, 'name2');

declare
  my_test test.tb_test_1%rowtype;
  cursor cs is
    select * from tb_test_1 for update;
begin

  for css in cs loop
    my_test.id   := css.id;
    my_test.name := css.name || 's';
    update tb_test_1 a
       set a.id = my_test.id, a.name = my_test.name
     where current of cs;
     commit;
  end loop;
  commit;

end;

则:ora-01002

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16179598/viewspace-531591/,如需转载,请注明出处,否则将追究法律责任。

下一篇: ibatis && ibatisnet
请登录后发表评论 登录
全部评论

注册时间:2008-12-27

  • 博文量
    316
  • 访问量
    666171