简体   繁体   English

PLSQL 中的瑞士工资单的校验位

[英]Check Digit for Swiss Pay Slips in PLSQL

I have a problem with Luhn Algorithm for Pay Slip in Swiss.我对瑞士工资单的 Luhn 算法有疑问。 I found an algorithm in C, Phyton, or Java Script but I don't know how to implement this algorithm on Oracle.我在 C、Phyton 或 Java 脚本中找到了一个算法,但我不知道如何在 Oracle 上实现这个算法。

http://dnando.github.io/blog/2014/09/23/check-digit-computation-swiss-pay-slips/ http://dnando.github.io/blog/2014/09/23/check-digit-computation-swiss-pay-slips/

http://www.hosang.ch/modulo10.aspx http://www.hosang.ch/modulo10.aspx

This page shows how to algorithm looks like.此页面显示了算法的外观。

public static int modulo10(string nummer)
{
    // 'nummer' darf nur Ziffern zwischen 0 und 9 enthalten!

    int[] tabelle = { 0, 9, 4, 6, 8, 2, 7, 1, 3, 5 };
    int uebertrag = 0;

    foreach (char ziffer in nummer)
        uebertrag = tabelle[(uebertrag + ziffer - '0') % 10];

    return (10 - uebertrag) % 10;
}

Do You know how to implement a table in PLSQL?你知道如何在 PLSQL 中实现一个表吗?

Thanks in advance for your help with this algorithm.提前感谢您对此算法的帮助。

You can use:您可以使用:

CREATE FUNCTION luhn_modulo(
  value IN VARCHAR2
) RETURN NUMBER DETERMINISTIC
IS
  offsets CONSTANT CHAR(10) := '0946827135';
  output  PLS_INTEGER := 0;
BEGIN
  FOR i IN 1 .. LENGTH( value ) LOOP
    output := SUBSTR( offsets, MOD(output + SUBSTR( value, i, 1 ), 10) + 1, 1 );
  END LOOP;
  RETURN MOD(10 - output, 10);
END;
/

Then:然后:

BEGIN
  DBMS_OUTPUT.PUT_LINE( luhn_modulo( '1' ) );
  DBMS_OUTPUT.PUT_LINE( luhn_modulo( '2' ) );
  DBMS_OUTPUT.PUT_LINE( luhn_modulo( '3' ) );
  DBMS_OUTPUT.PUT_LINE( luhn_modulo( '4' ) );
  DBMS_OUTPUT.PUT_LINE( luhn_modulo( '1234' ) );
  DBMS_OUTPUT.PUT_LINE( luhn_modulo( '000' ) );
END;
/

Outputs:输出:

 1 6 4 2 7 0

db<>fiddle here db<> 在这里摆弄

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM