Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1372437
  • 博文数量: 205
  • 博客积分: 6732
  • 博客等级: 准将
  • 技术积分: 2835
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-04 17:59
文章分类

全部博文(205)

文章存档

2016年(1)

2015年(10)

2014年(1)

2013年(39)

2012年(23)

2011年(27)

2010年(21)

2009年(55)

2008年(28)

我的朋友

分类: Oracle

2009-08-19 19:04:21

CREATE OR REPLACE PROCEDURE P_PNT_REPORTCARD
(
option_type in char,--1挂失 2解挂

check_type in char, --1身份证 2 会员卡密码

member_id in number,--会员编号

latn_id in varchar2,--本地网

card_pwd in varchar2,--会员卡密码

returnMsg out varchar2
)
as
    cardState TB_MEM_MEM_CARD_RES_REL.MEMBER_CARD_STATE%type;
    --cardState char(4);

    is_valid number(4);
    v_sql varchar2(2000);
    v_temp varchar2(2000);
begin
--传的值进行非空验证

if (option_type !=1 and option_type!=2) or (check_type!=1 and check_type!=2) or (member_id is null) or (latn_id is null)
then
   returnMsg := '调用该存储过程,传的参数不对!';
   return;
end if;
if(check_type='2') then
   if(card_pwd is null) then
     returnMsg := '采用会员卡验证,会员卡密码不能为空!';
     return;
   end if;
end if;
--查询会员卡状态

v_sql:='select MEMBER_CARD_STATE from TB_MEM_MEM_CARD_RES_REL where MEMBER_ID =' || member_id;
--dbms_output.put_line(v_sql||CHR(10));

execute immediate v_sql into cardState;
v_sql := 'select count(MEMBER_ID) from TB_MEM_MEMBER_' || latn_id || ' where MEMBER_ID={memberid} and PASSWORD={pwd}';
v_sql := replace(v_sql,'{memberid}' ,member_id);
v_sql := replace(v_sql,'{pwd}' ,card_pwd);
   --挂失

   if option_type = '1' then
     begin
        if cardState= '1' then
          begin
              if check_type ='1' then
                   v_temp :='update TB_MEM_MEM_CARD_RES_REL set MEMBER_CARD_STATE=3 where MEMBER_ID =' || member_id;
                   execute immediate v_temp;
                   returnMsg := '挂失成功!';
              elsif check_type ='2' then
              begin
                  --立即执行

                  execute immediate v_sql into is_valid;
                  if is_valid =1 then
                     v_temp :='update TB_MEM_MEM_CARD_RES_REL set MEMBER_CARD_STATE=3 where MEMBER_ID =' || member_id;
                     execute immediate v_temp;
                     returnMsg := '挂失成功!';
                  else
                      returnMsg := '会员卡密码不正确!';
                      return;
                  end if;
               end;
               end if;
          end;
        else
            returnMsg := '会员卡状态不是有效状态不能挂失!';
            return;
        end if;
     end;
   --解挂

   elsif option_type = '2' then
     begin
       if cardState= '3' then
         begin
            if check_type ='1' then
               v_temp :='update TB_MEM_MEM_CARD_RES_REL set MEMBER_CARD_STATE=1 where MEMBER_ID =' || member_id;
               execute immediate v_temp;
               returnMsg := '解挂成功!';
            elsif check_type ='2' then
               begin
                  --立即执行

                  execute immediate v_sql into is_valid;
                  if is_valid =1 then
                     v_temp :='update TB_MEM_MEM_CARD_RES_REL set MEMBER_CARD_STATE=1 where MEMBER_ID =' || member_id;
                     execute immediate v_temp;
                     returnMsg := '解挂成功!';
                  else
                      returnMsg := '会员卡密码不正确!';
                      return;
                  end if;
               end;
            end if;
         end;
       else
           returnMsg := '会员卡状态不是挂失状态不能解挂!';
           return;
       end if;
     end;
   end if;
   commit;
   exception
     when others then
         returnMsg := '内部错误'|| sqlerrm;
         --dbms_output.put_line('ky' || sqlerrm);

         rollback;
         return;
end P_PNT_REPORTCARD;

阅读(2696) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~