游标是查询语句返回的记录集, 
  简单的说,是供查询用的,
  但是游标可以逐行定位,完成你需要的操作,比如存取和更新数据,
同时可以给游标加锁,比如For update,防止其他会话改变当前活动集中的数据行。
   
  好好学一下游标的知识吧

解决方案 »

  1.   

    但是象sqlserver数据库,游标是允许更新的呀
    另外好像是for update选项就是打开一个可更新游标,但具体语句如何写,
    不知道,
      

  2.   

    和Sql Server不一样,在Oracle里,for update 就是加锁,防止别人修改。
      

  3.   

    select * from 表 for update nowait
      

  4.   

    那下边的语句会产生等待么:
    declare 
    v1 number(1);
    v2 number(1);
    nid number;
    cursor cur as select select id,a1,a2 from a;
    begin
      open cur
      loop
        fatch cur into nid,v1,v2;
        exit when cur %notfound;
        if v1>v2 then
          update a set a3=v1 where id=nid;
        els
          update a set a3=v2 where id=nid;
        end if;
      end loop;
    end
      

  5.   

    如果用下边的语句会产生等待么:
    declare 
    v1 number(1);
    v2 number(1);
    nid number;
    cursor cur as select select id,a1,a2,a3 from a;
    begin
      open cur
      loop
        fatch cur into nid,v1,v2;
        exit when cur %notfound;
        if v1>v2 then
          cur.a3=v1;--?不知道语句是否正确,请指教
        els
          cur.a3=v2;--?不知道语句是否正确,请指教
        end if;
      end loop;
    end
      

  6.   

    if v1>v2 then
          cur.a3=v1;--?不知道语句是否正确,请指教
        els
          cur.a3=v2;--?不知道语句是否正确,请指教
        end if;有这种写法吗?
    Oracle里不这样写,只能重游标里读取值。