Этот результат применим для числовых последовательностей каждой длины.
CREATE OR REPLACE luhn_num (orig_num IN NUMBER)
RETURN STRING IS
num_len NUMBER(20) := length(orig_num);
result_num NUMBER(10);
i NUMBER(10);
temp_num NUMBER(10);
sum_num NUMBER(10) := 0;
BEGIN
IF MOD(num_len,2) = 0 THEN
FOR i IN 1..num_len LOOP
IF MOD(i,2) = 0 THEN
IF length(to_number(substr(orig_num,i,1))*2) > 1 THEN
sum_num := sum_num + to_number(substr(to_number(substr(orig_num,i,1))*2,1,1)) + to_number(substr(to_number(substr(orig_num,i,1))*2,2,1));
ELSE
sum_num := sum_num + (to_number(substr(orig_num,i,1))*2);
END IF;
ELSE
sum_num := sum_num + to_number(substr(orig_num,i,1));
END IF;
END LOOP;
ELSE
FOR i IN 1..num_len LOOP
IF MOD(i,2) <> 0 THEN
IF length(to_number(substr(orig_num,i,1))*2) > 1 THEN
sum_num := sum_num + to_number(substr(to_number(substr(orig_num,i,1))*2,1,1)) + to_number(substr(to_number(substr(orig_num,i,1))*2,2,1));
ELSE
sum_num := sum_num + (to_number(substr(orig_num,i,1))*2);
END IF;
ELSE
sum_num := sum_num + to_number(substr(orig_num,i,1));
END IF;
END LOOP;
END IF;
temp_num := 10 - to_number(substr(sum_num,length(sum_num),1));
IF temp_num = 10 THEN
result_num := 0;
ELSE
result_num := temp_num;
END IF;
RETURN result_num ;
END;