当前位置: 代码迷 >> Oracle开发 >> oracle 存储过程 游标的有关问题
  详细解决方案

oracle 存储过程 游标的有关问题

热度:165   发布时间:2016-04-24 06:26:33.0
oracle 存储过程 游标的问题
create or replace procedure test_procedure(planetimetableid in integer , gid in integer ,addpeo in integer,peoCount in integer
) is
cursor a_cursor is
select id from seats_info where id in(select id from (select t.*,rownum rn from seats_info t where t.istate ='0' and t.planetimetableid =planetimetableid 
and t.isdelete = '0' ) where rn<=peoCount) for update;
begin
for a_cur in a_cursor loop
update seats_info set istate = '1',lastudpdate = sysdate,lastudppeoid =addpeo where id = a_cur.id;
insert into passenger_info(gid, seatsid, addpeo)values(gid,a_cur.id ,addpeo );
insert into test(sid,pid, cou)values(a_cur.id,planetimetableid,peoCount);
end loop;
commit;
end test_procedure;
单独执行查询语句时 select id from seats_info where id in(select id from (select t.*,rownum rn from seats_info t where t.istate ='0' and t.planetimetableid =63 
and t.isdelete = '0' ) where rn<=2) 能返回正确的数据
但是在存储过程中游标取出来的a_cui.id 数据不正确

求大神解答~~~帮忙看看哪里写错了
------解决思路----------------------
游标定义那里为什么要加for update?
------解决思路----------------------
begin
for a_cur in a_cursor loop
update seats_info set istate = '1',lastudpdate = sysdate,lastudppeoid =addpeo where id = a_cur.id;
insert into passenger_info(gid, seatsid, addpeo)values(gid,a_cur.id ,addpeo );
insert into test(sid,pid, cou)values(a_cur.id,planetimetableid,peoCount);
end loop;

把这段话直接拿去执行下,用dbms_output.put_line 打印下,也许可以看出问题。
  相关解决方案