covert Verhoeffalgorithm into SQL stored procedere

  • CAn any body help me by converting the below function into sql stored procedure

    function CalculateVerhoeffDigit(p_input in varchar2)

    return smallint

    is

    PV_D constant varchar2(100) := '0123456789123406789523401789563401289567401239567859876043216598710432765982104387659321049876543210';

    PV_P constant varchar2(80) := '01234567891576283094580379614289160435279453126870428657390127938064157046913258';

    PV_INV constant char(10) := '0432156789';

    lv_c integer := 0;

    lv_m integer;

    lv_n varchar2(255);

    lv_i integer := 0;

    lv_len integer := length(p_input);

    begin

    select reverse(p_input)

    into lv_n

    from dual;

    while lv_i < lv_len loop

    lv_m := to_number(substr(PV_P, (mod((lv_i + 1),8) * 10) + to_number(substr(lv_n, lv_i + 1, 1)) + 1, 1));

    lv_c := to_number(substr(PV_D, (lv_c * 10 + lv_m + 1), 1));

    lv_i := lv_i + 1;

    end loop;

    lv_c := to_number(substr(PV_INV, lv_c + 1, 1));

    return lv_c;

    end CalculateVerhoeffDigit;

  • Create function CalculateVerhoeffDigit(@p_input varchar(Max))

    returns smallint

    As

    Begin

    Declare @PV_D varchar(100),@PV_P varchar(80),@PV_INV varchar(10)

    Declare @lv_c Int, @lv_m Int,@lv_n varchar(255), @lv_i Int,@lv_len Int

    Set @PV_D= '0123456789123406789523401789563401289567401239567859876043216598710432765982104387659321049876543210'

    Set @PV_P= '01234567891576283094580379614289160435279453126870428657390127938064157046913258'

    Set @PV_INV= '0432156789'

    Set @lv_c= 0

    Set @lv_i= 0

    Set @lv_len= Len(@p_input)

    Set @lv_n= reverse(@p_input)

    -- into @lv_n

    -- from dual; ????

    while @lv_i < @lv_len

    Begin

    -- Set @lv_m = to_number(substr(@PV_P, (mod((@lv_i + 1),8) * 10) + to_number(substr(@lv_n, @lv_i + 1, 1)) + 1, 1));

    -- Set @lv_c = to_number(substr(@PV_D, (@lv_c * 10 + @lv_m + 1), 1));

    Set @lv_m = Cast(substring(@PV_P, (((@lv_i + 1)%8) * 10) + cast(substring(@lv_n, @lv_i + 1, 1) as Int) + 1, 1)

    as Int)

    Set @lv_c = cast(substring(@PV_D, (@lv_c * 10 + @lv_m + 1), 1) as int)

    Set @lv_i = @lv_i + 1;

    end --loop;

    Set @lv_c = Cast((substring(@PV_INV, @lv_c + 1, 1)) as Int)

    return (@lv_c)

    end --CalculateVerhoeffDigit;

  • wasn't there something in the Development folder on this?

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply