Oracle source code to verify the correctness of the bank card number

Source: Internet
Author: User

CREATE OR REPLACE FUNCTION checkbankcard (P_bankcard in VARCHAR2)
Return VARCHAR2--Returns OK when correct, otherwise returns the correct check code
Is
Curval number: = 0;
Total number: = 0;
Everyother number: = 1;
V_end number;
BEGIN
IF (P_bankcard is NULL) then
RETURN ' null ';
End IF;
For i in reverse 1.. (LENGTH (P_bankcard)-1) loop
Curval: = SUBSTR (P_bankcard, I, 1);
IF everyother = 1 Then
Everyother: = 0;
Curval: = Curval * 2;
IF (Curval > 9) Then
Curval: = curval-9;
End IF;
Else
Everyother: = 1;
End IF;
Total: = all + Curval;
End Loop;
IF MOD (total, ten) = 0 Then
V_end: = 0;
ELSE
v_end:= 10-mod (total, 10);
END IF;
If To_char (v_end) = substr (P_BANKCARD,LENGTHB (P_bankcard), 1) Then
return ' OK ';
Else
return To_char (V_end);
End If;
End

Oracle source code to verify the correctness of the bank card number

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.