游标是查询语句返回的记录集,
简单的说,是供查询用的,
但是游标可以逐行定位,完成你需要的操作,比如存取和更新数据,
同时可以给游标加锁,比如For update,防止其他会话改变当前活动集中的数据行。
好好学一下游标的知识吧
简单的说,是供查询用的,
但是游标可以逐行定位,完成你需要的操作,比如存取和更新数据,
同时可以给游标加锁,比如For update,防止其他会话改变当前活动集中的数据行。
好好学一下游标的知识吧
另外好像是for update选项就是打开一个可更新游标,但具体语句如何写,
不知道,
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
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
cur.a3=v1;--?不知道语句是否正确,请指教
els
cur.a3=v2;--?不知道语句是否正确,请指教
end if;有这种写法吗?
Oracle里不这样写,只能重游标里读取值。