码迷,mamicode.com
首页 > 其他好文 > 详细

判断用户是否定购某sp业务——存储过程

时间:2015-09-15 14:28:37      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

create or replace procedure pro_check_sp(v_servnumber in varchar2,
                                         v_spid       in varchar2,
                                         v_spbizid    in varchar2,
                                         v_result     out varchar2
                                       
                                         ) is
  --判断用户是否定购某sp业务,已订购返回yes,否则为no
  n_region  number(5);
  n_subsid  number(18);
  int_count number(10);
  my_region_err exception;
  my_subsid_err exception;
begin
  v_result  := ‘‘;
  int_count := 0;
  ---取region;
  SELECT DISTINCT REGION
    INTO n_region
    FROM TBCS.REC_SERVNUMBER_REGION
   WHERE BEGINNUM <= v_servnumber
     AND ENDNUM >= v_servnumber;
  if (n_region is null) then
    --抛出异常后过程会自动退出
    raise my_region_err;
  end if;
  --取subsid
  select count(*)
    into int_count
    from (select subsid
             from tbcs.subscriber
            where servnumber = v_servnumber
              and region = n_region
              and active = 1
           union
           select subsid
             from tbcs.subscriber
            where servnumber = v_servnumber
              and region = n_region
              and active = 1);
  if int_count != 1 then
    raise my_subsid_err;
  end if;
  select subsid
    into n_subsid
    from (select subsid
             from tbcs.subscriber
            where servnumber = v_servnumber
              and region = n_region
              and active = 1
           union
           select subsid
             from tbcs.subscriber@TBCSA_B.HEBEI.MOBILE.COM
            where servnumber = v_servnumber
              and region = n_region
              and active = 1);
  --取定购关系
  int_count := 0;
  select count(*)
    into int_count
    from (select t.*
             from tbcs.subs_spservice t
            where t.subsid = n_subsid
              and t.region = n_region
              and t.spid = v_spid
              and t.spbizid = v_spbizid
              and (t.enddate >= sysdate or t.enddate is null)
           union
           select t.*
             from tbcs.subs_spservice@TBCSA_B.HEBEI.MOBILE.COM t
            where t.subsid = n_subsid
              and t.region = n_region
              and t.spid = v_spid
              and t.spbizid = v_spbizid
              and (t.enddate >= sysdate or t.enddate is null));
  if int_count >= 1 then
    v_result := ‘yes‘;
  else
    v_result := ‘no‘;
  end if;
exception
  when my_region_err then
    v_result := ‘region_err‘;
  when my_subsid_err then
    v_result := ‘subsid_err‘;
 
end pro_check_sp;

判断用户是否定购某sp业务——存储过程

标签:

原文地址:http://www.cnblogs.com/dosttyy/p/4810046.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!