Create Or Replace Function IDCARD15TO18(CARD Varchar2) Return Varchar2 Is Type TIARRAY Is Table Of Integer; Type TCARRAY Is Table Of Char(1); RESULTS Varchar2(18); W TIARRAY; -- 数字数组 A TCARRAY; -- 字符数组 S Integer; Begin If CARD Is Null Then Return ''; End If; If LENGTH(CARD) <> 15 Then Return CARD; End If; W := TIARRAY(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1); A := TCARRAY('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); RESULTS := SUBSTR(CARD, 1, 6) || '19' || SUBSTR(CARD, 7, 9); S := 0; Begin For I In 1 .. 17 Loop S := S + To_Number(SUBSTR(RESULTS, I, 1)) * W(I); End Loop; Exception When Others Then Return ''; End; S := S Mod 11; RESULTS := RESULTS || A(S + 1); Return(RESULTS); End IDCARD15TO18;
标签:End,位转,Return,RESULTS,SUBSTR,Varchar2,18,15,CARD From: https://www.cnblogs.com/erguai/p/16836087.html