返回信息流从表A里取几列数送出,取走后标记已读.
取的时候的条件:
open v_cursor for
select * from (select T1.* from T1 where A1=0 order by B1 desc) where rownum<=100;
然后想在T1里更新这100列数据,set A1=1,那update语句应该怎么写?
这是一条镜像帖。来源:北邮人论坛 / database / #5181同步于 2011/1/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖
问一个update的条件...
ooxx
2011/1/25镜像同步9 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
暂时解决了,方法是利用T1里的某个序列号,
update T1 set A1=1 where seq1||seq2||seq3 in (select seq1||seq2||seq3 from (select * from T1 where A1=0 order by B1 desc) where rownum<100);
【 在 ooxx 的大作中提到: 】
: 暂时解决了,方法是利用T1里的某个序列号,
: update T1 set A1=1 where seq1||seq2||seq3 in (select seq1||seq2||seq3 from (select * from T1 where A1=0 order by B1 desc) where rownum<100);
: --
: ...................
还有个问题,取值和update是在一个存储过程的里的话,如果T1表数据随时更新,那这个存储过程取值取到的和update的数据能不能确保是同一组数据?对rownum不太熟...
用rowid试试?
【 在 ooxx ((o_o)(x_x)) 的大作中提到: 】
: 还有个问题,取值和update是在一个存储过程的里的话,如果T1表数据随时更新,那这个存储过程取值取到的和update的数据能不能确保是同一组数据?对rownum不太熟...
【 在 IkariShinji 的大作中提到: 】
: 用rowid试试?
: 【 在 ooxx ((o_o)(x_x)) 的大作中提到: 】
: : 还有个问题,取值和update是在一个存储过程的里的话,如果T1表数据随时更新,那这个存储过程取值取到的和update的数据能不能确保是同一组数据?对rownum不太熟...
: ...................
啥?
我就是问我在1楼那种方法,第一步select xxxx rownum<100,第二步 update xxx where xxxx rownum < 100.
在T1表还随时更新(insert数据)的情况下,能不能保证取出的数据都会被标记?或者说两步分别用的rownum<100这个条件取到的数据会不会变?
肯定会变,rownum<100指前99条记录,如果insert新记录,前99条肯定会变的
【 在 ooxx 的大作中提到: 】
: 啥?
: 我就是问我在1楼那种方法,第一步select xxxx rownum<100,第二步 update xxx where xxxx rownum < 100.
: 在T1表还随时更新(insert数据)的情况下,能不能保证取出的数据都会被标记?或者说两步分别用的rownum<100这个条件取到的数据会不会变?
【 在 wuquehua 的大作中提到: 】
: 肯定会变,rownum<100指前99条记录,如果insert新记录,前99条肯定会变的
: 【 在 ooxx 的大作中提到: 】
: : 啥?
: ...................
晕,忘记B1那个排序了,后面插的B1不一样的话肯定变...
那应该怎么写?
用游标试了一下,失败了...
open v_cursor for
select * from (select sendmt.* from sendmt where processflag=0 order by priority desc) where rownum<maxrow;
return_list:=v_cursor;
LOOP
FETCH v_cursor INTO o_cursor;
EXIT WHEN v_cursor%NOTFOUND;
update sendmt set processflag=1 where seq1||seq2||seq3=o_cursor.seq1||o_cursor.seq2||o_cursor.seq3;
END LOOP;
close v_cursor;
状态倒是改了,可是数据没读成功...
declare
cursor o_cursor is
select * from (select sendmt.* from sendmt where processflag=0 order by priority desc) where rownum<maxrow;
begin
for v_cursor in o_cursor loop
update sendmt set processflag=1 where seq1||seq2||seq3=v_cursor.seq1||v_cursor.seq2||v_cursor.seq3;
commit;
end loop;
end;
用这种方式读游标试试
【 在 ooxx 的大作中提到: 】
: 用游标试了一下,失败了...
: open v_cursor for
: select * from (select sendmt.* from sendmt where processflag=0 order by priority desc) where rownum<maxrow;
: ...................
【 在 wuquehua 的大作中提到: 】
: declare
: cursor o_cursor is
: select * from (select sendmt.* from sendmt where processflag=0 order by priority desc) where rownum<maxrow;
: ...................
v_cursor怎么定义?