您的位置:首页 > 数据库 > Oracle

Oracle编程,遇到并发的情况处理

2015-07-20 22:13 411 查看
在实际业务处理,特别是在统计报表数据时,经常会遇到并发的情况。

在实际工作中,我遇到过类似的情况,大概情况是这样的:

在统计报表的时候需要,用户前台点击生成,当2个用户登陆,同时点击报表生成时,会出现报表数据重复的现在。这当然是,一个用户点击生成时,后台数据还没有完全跑完,然后有一个用户点击,又重新跑刚才的同一个过程,并且入参都一样,这就导致重复数据的出现。

现在想到一个处理方法如下:

create table tb_test (is_yx varchar2(1));

select t.is_yx into vi_result1

from tb_test t;

if vi_result1=1 then

loop

select t.is_yx into vi_result1

from tb_test t;

if vi_result1=1 then

select sysdate into start_time from dual;

loop

select sysdate into end_time from dual;

exit when (end_time-start_time)*24*60*60 >=60;

end loop;

else

exit;

end if;

end loop;

end if;

在过程里,处理数据前加上该段判断,紧接着

update tb_test t set t.is_yx=1;

commit;

数据处理完再做如下处理

update tb_test t set t.is_yx=0;

commit;

这样就可以一直等待该数据处理完再处理下一个
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: