create or replace function changeaac002_15to18
(
ls_card varchar2
)
return varchar2 is
ls_newcard varchar2(18);
a1 number(10);
a2 number(10);
a3 number(10);
a4 number(10);
a5 number(10);
a6 number(10);
a7 number(10);
a8 number(10);
a9 number(10);
a10 number(10);
a11 number(10);
a12 number(10);
a13 number(10);
a14 number(10);
a15 number(10);
a16 number(10);
a17 number(10);
a18 number(10);
w1 number(10);
w2 number(10);
w3 number(10);
w4 number(10);
w5 number(10);
w6 number(10);
w7 number(10);
w8 number(10);
w9 number(10);
w10 number(10);
w11 number(10);
w12 number(10);
w13 number(10);
w14 number(10);
w15 number(10);
w16 number(10);
w17 number(10);
w18 number(10);
i number(10);
v_sum number(10);
ls_final0 varchar2(18);
ls_final1 varchar2(18);
ls_final2 varchar2(18);
ls_final3 varchar2(18);
ls_final4 varchar2(18);
ls_final5 varchar2(18);
ls_final6 varchar2(18);
ls_final7 varchar2(18);
ls_final8 varchar2(18);
ls_final9 varchar2(18);
ls_final10 varchar2(18);
begin
if (length(ls_card) <> 15) then
return ls_card;
end if;
ls_newcard := substr(ls_card,1,6)||‘19‘||substr(ls_card,7,9);
a1 := to_number(substr(ls_newcard,1,1));
a2 := to_number(substr(ls_newcard,2,1));
a3 := to_number(substr(ls_newcard,3,1));
a4 := to_number(substr(ls_newcard,4,1));
a5 := to_number(substr(ls_newcard,5,1));
a6 := to_number(substr(ls_newcard,6,1));
a7 := to_number(substr(ls_newcard,7,1));
a8 := to_number(substr(ls_newcard,8,1));
a9 := to_number(substr(ls_newcard,9,1));
a10 := to_number(substr(ls_newcard,10,1));
a11 := to_number(substr(ls_newcard,11,1));
a12 := to_number(substr(ls_newcard,12,1));
a13 := to_number(substr(ls_newcard,13,1));
a14 := to_number(substr(ls_newcard,14,1));
a15 := to_number(substr(ls_newcard,15,1));
a16 := to_number(substr(ls_newcard,16,1));
a17 := to_number(substr(ls_newcard,17,1));
w1 := 7 ;
w2 := 9 ;
w3 :=10 ;
w4 := 5 ;
w5 := 8 ;
w6 := 4 ;
w7 := 2 ;
w8 := 1 ;
w9 := 6 ;
w10 := 3 ;
w11 := 7 ;
w12 := 9 ;
w13 :=10 ;
w14 := 5 ;
w15 := 8 ;
w16 := 4 ;
w17 := 2 ;
w18 := 1 ;
ls_final0 := ‘1‘;
ls_final1 := ‘0‘;
ls_final2 := ‘X‘;
ls_final3 := ‘9‘;
ls_final4 := ‘8‘;
ls_final5 := ‘7‘;
ls_final6 := ‘6‘;
ls_final7 := ‘5‘;
ls_final8 := ‘4‘;
ls_final9 := ‘3‘;
ls_final10 :=‘2‘;
v_sum := 0;
v_sum := v_sum + a1*w1;
v_sum := v_sum + a2*w2;
v_sum := v_sum + a3*w3;
v_sum := v_sum + a4*w4;
v_sum := v_sum + a5*w5;
v_sum := v_sum + a6*w6;
v_sum := v_sum + a7*w7;
v_sum := v_sum + a8*w8;
v_sum := v_sum + a9*w9;
v_sum := v_sum + a10*w10;
v_sum := v_sum + a11*w11;
v_sum := v_sum + a12*w12;
v_sum := v_sum + a13*w13;
v_sum := v_sum + a14*w14;
v_sum := v_sum + a15*w15;
v_sum := v_sum + a16*w16;
v_sum := v_sum + a17*w17;
i := mod(v_sum,11);
if i = 0 then
ls_newcard := ls_newcard||ls_final0;
elsif i = 1 then
ls_newcard := ls_newcard|| ls_final1;
elsif i = 2 then
ls_newcard := ls_newcard|| ls_final2;
elsif i = 3 then
ls_newcard := ls_newcard|| ls_final3;
elsif i = 4 then
ls_newcard := ls_newcard|| ls_final4;
elsif i = 5 then
ls_newcard := ls_newcard|| ls_final5;
elsif i = 6 then
ls_newcard := ls_newcard|| ls_final6;
elsif i = 7 then
ls_newcard := ls_newcard|| ls_final7;
elsif i = 8 then
ls_newcard := ls_newcard|| ls_final8;
elsif i = 9 then
ls_newcard := ls_newcard|| ls_final9;
elsif i = 10 then
ls_newcard := ls_newcard|| ls_final10;
end if;
return ls_newcard;
exception when others then
return ls_card ;
end ;
原文地址:https://www.cnblogs.com/xunyi/p/11594188.html