/*
卡号码组成为:19 YY PP F X1 X2 X3 X4 X5 X6 X7 X8 X9 共计16位
号码的格式定义如下:
19广东省代码
YY编制为VIP卡生产年号(今年11)
PPVIP卡生产批次标志(按照厂家接到生产数据的月份定,统一填写为01)
F1代表钻卡,2代表金卡,3代表银卡
X1 X2各市区域代码
X3为客户类型代码,1为积分客户,2为重要客户,3为集团客户,4为内部测试客户,5、优质客户 6为套餐办理客户,7尊享老客户(即十年老客户升级VIP资格的),9其他。
X4 X5 X6 X7 X8 X9客户编号:6位号码按顺序产生
191101F12XYYYYYY
为客户类型代码,
1为积分客户,2为重要客户,3为集团客户,4为内部测试客户,5、优质客户
6为套餐办理客户,7尊享老客户(即十年老客户升级VIP资格的),9其他。
1积分评定6965
1积分评定(优质客户)4107
5老客户升级878
5老客户升级(优质客户)444
4内部测试客户24
5普通老客户48751
6套餐评定29
2特殊评定1118
2特殊评定(优质客户)46
*/
/*
----创建序列SEQ_NO
create sequence SEQ_NO
minvalue 1
maxvalue 999999
start with 1
increment by 1
cache 20
order;
----将之前全部结果按分配后的卡号排序
create table tb_yb_zj201103160003_no nologging as
select
seq_no.nextval seq_code ,
x.servnumber ,
x.pd_type ,
x.card_type ,
x.card_no
from (select a.servnumber ,
case when a.pd_type = '积分评定' then '积分评定'
when a.pd_type = '积分评定(优质客户)' then '积分评定'
when a.pd_type = '老客户升级' then '老客户升级'
when a.pd_type = '老客户升级(优质客户)' then '老客户升级'
when a.pd_type = '内部测试客户' then '内部测试客户'
when a.pd_type = '普通老客户' then '普通老客户'
when a.pd_type = '套餐评定' then '套餐评定'
when a.pd_type = '特殊评定' then '特殊评定'
when a.pd_type = '特殊评定(优质客户)' then '特殊评定' end pd_type ,
a.card_type ,
case when length(a.code2) = 1 then a.code||'00000'||a.code2
when length(a.code2) = 2 then a.code||'0000'||a.code2
when length(a.code2) = 3 then a.code||'000'||a.code2
when length(a.code2) = 4 then a.code||'00'||a.code2
when length(a.code2) = 5 then a.code||'0'||a.code2
when length(a.code2) = 6 then a.code||a.code2 end card_no
from tb_yb_zj201103160003_ser3 a
order by card_no
) x
;
----生成新的原始明细表
create table tb_yb_jxy_vipser nologging as
select
a.seq_code ,
a.servnumber ,
a.pd_type ,
a.card_type
from tb_yb_zj201103160003_no a
;
*/
/*
18820700155特殊评定金卡
13790981111特殊评定金卡
18820819999特殊评定金卡
18820628666特殊评定金卡
select
count(a.seq_code)
from tb_yb_jxy_vipser a
where a.servnumber in
('18820700155',
'13790981111',
'18820819999',
'18820628666'
)
;
0
*/
----将新增号码导入原始明细表中
insert into tb_yb_jxy_vipser values (seq_no.nextval , '18820700155' , '特殊评定' , '金卡') ;
insert into tb_yb_jxy_vipser values (seq_no.nextval , '13790981111' , '特殊评定' , '金卡') ;
insert into tb_yb_jxy_vipser values (seq_no.nextval , '18820819999' , '特殊评定' , '金卡') ;
insert into tb_yb_jxy_vipser values (seq_no.nextval , '18820628666' , '特殊评定' , '金卡') ;
commit ;
----根据评定类型、VIP类型确定卡号前10位及对应序号
create table tb_yb_jxy_vipser2 nologging as
select a.seq_code , --序号
a.servnumber , --号码
a.pd_type , --评定类型(ITC)
a.card_type , --2011卡类
a.style||a.style2 code , --卡号前10位
row_number () over (partition by a.style||a.style2 order by a.seq_code) code1 --序列号
from (select
x.seq_code ,
x.servnumber ,
x.pd_type ,
x.card_type ,
case when x.card_type = '钻石卡' then 191101112
when x.card_type = '金卡' then 191101212
when x.card_type = '银卡' then 191101312 end style ,
case when x.pd_type = '积分评定' then 1
when x.pd_type = '积分评定(优质客户)' then 1
when x.pd_type = '老客户升级' then 5
when x.pd_type = '老客户升级(优质客户)' then 5
when x.pd_type = '内部测试客户' then 4
when x.pd_type = '普通老客户' then 5
when x.pd_type = '套餐评定' then 6
when x.pd_type = '特殊评定' then 2
when x.pd_type = '特殊评定(优质客户)' then 2 end style2
from tb_yb_jxy_vipser x
) a
;
----中间汇总数据
create table tb_yb_jxy_vipser3
(
seq_code number(5) , /*序号*/
servnumber varchar2(20) , /*号码*/
pd_type varchar2(64) , /*评定类型(ITC)*/
card_type varchar2(64) , /*2011卡类*/
code number(10) , /*卡号前10位*/
code2 number(5) /*客户编号序列号*/
)
;
----银卡号码处理(2、银卡的X9(最后一位)避免用4、7)
declare
v_seq_code number(5) ;
v_servnumber varchar2(20) ;
v_pd_type varchar2(64) ;
v_card_type varchar2(64) ;
v_code varchar2(20) ;
v_code1 number(5) ;
v_code2 number(5):=0 ;
cursor v_cursor is
select a.seq_code ,
a.servnumber ,
a.pd_type ,
a.card_type ,
a.code ,
a.code1
from tb_yb_jxy_vipser2 a
where a.card_type = '银卡'
;
begin
open v_cursor;
loop
fetch v_cursor into v_seq_code,v_servnumber,v_pd_type,v_card_type,v_code,v_code1;
exit when v_cursor%notfound;
v_code2:=v_code2+1;
if v_code1=1 then
v_code2:=1;
elsif mod(v_code2,10)=4 or mod(v_code2,10)=7 then
v_code2:=v_code2+1;
end if;
insert into tb_yb_jxy_vipser3 values
(v_seq_code,v_servnumber,v_pd_type,v_card_type,v_code,v_code2);
commit ;
end loop ;
close v_cursor ;
end
;
----钻石卡、金卡号码处理(1、全球通钻石卡、金卡的X9(最后一位) 要求为8)
insert into tb_yb_jxy_vipser3 nologging
select
s.seq_code ,
s.servnumber ,
s.pd_type ,
s.card_type ,
s.code ,
(s.code1-1)*10+8
from tb_yb_jxy_vipser2 s
where s.card_type in ('钻石卡','金卡')
;
commit ;
/*
select distinct
card_type ,
mod(code2,10)
from tb_yb_jxy_vipser3
order by card_type , mod(code2,10)
;
金卡8
银卡0
银卡1
银卡2
银卡3
银卡5
银卡6
银卡8
银卡9
钻石卡8
select
count(code||code2) ,
count(distinct code||code2)
from tb_yb_jxy_vipser3
;
6236662366
*/
----生成全部号码的结果
create table tb_yb_jxy_vipser4 nologging as
select
a.seq_code ,
a.servnumber ,
a.pd_type ,
a.card_type ,
case when length(a.code2) = 1 then a.code||'00000'||a.code2
when length(a.code2) = 2 then a.code||'0000'||a.code2
when length(a.code2) = 3 then a.code||'000'||a.code2
when length(a.code2) = 4 then a.code||'00'||a.code2
when length(a.code2) = 5 then a.code||'0'||a.code2
when length(a.code2) = 6 then a.code||a.code2 end card_no
from tb_yb_jxy_vipser3 a
order by a.seq_code
;
/*
select count(card_no) , count(distinct card_no)
from tb_yb_jxy_vipser4
;
6236662366
*/
----导出数据
select
a.seq_code ,
a.servnumber ,
a.pd_type ,
a.card_type ,
a.card_no
from tb_yb_jxy_vipser4 a
where a.servnumber in
('18820700155',
'13790981111',
'18820819999',
'18820628666'
)
;
----更新原始明细表
truncate table tb_yb_jxy_vipser drop storage ;
insert into tb_yb_jxy_vipser nologging
select
a.seq_code ,
a.servnumber ,
a.pd_type ,
a.card_type
from tb_yb_jxy_vipser4 a
;
----
drop table tb_yb_jxy_vipser purge ;
drop table tb_yb_jxy_vipser2 purge ;
drop table tb_yb_jxy_vipser3 purge ;
drop table tb_yb_jxy_vipser4 purge ;