`
MITME
  • 浏览: 2802 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

mysql存储过程

阅读更多
drop procedure if exists pim_user_update_memory;
create procedure pim_user_update_memory()
begin
  declare lastupdate_in_memeory  varchar(40);
  declare v_userid varchar(40);
  declare flag default 0;
  declare counts int default 0;
declare result_in_cursor cursor for select PIM_USER.user_id from pim_user where PIM_USER.lastupdate > lastupdate_in_memory;

 
  select count(PIM_USER_MEMORY.userid) from PIM_USER_MEMORY into counts;
declare continue handler for sqlstate '02000' set flag = 1;

IF counts = 0 then
  insert into PIM_USER_MEMORY select * from PIM_USER;
else
begin
select MAX(PIM_USER_MEMORY.lastupdate) from PIM_USER_MEMORY into lastupdate_in_memeory;
open result_in_memery;
fetch result_in_memory into v_userid;
        while v_userid is not null do
    delete from PIM_USER_MEMORY where PIM_USER_MEMORY.USER_ID = v_userid;
insert into PIM_USER_MEMORY select * from PIM_USER where PIM_USER.USER_ID = v_userid;
fetch result_in_memory into v_userid;
end while;
close result_in_memory;
end;
end if;
end; 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics