Results 1 to 4 of 4

Thread: Hash Function

  1. #1
    Join Date
    Feb 2009
    Posts
    4

    Unanswered: Hash Function

    hello guys,

    I have a problem - I need to make anonymous some tabledata. I'd like to use hash-functions. Is there in db2, something like in oracle: DBMS_UTILITY.GET_HASH_VALUE(...)?

    Thank you very much.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    There's no built-in function, but you can easily create one for yourself, as described here: datori Top 5 SQL statements
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    May 2007
    Location
    somewhere in dbforums
    Posts
    221
    Quote Originally Posted by Vovan
    hello guys,

    I have a problem - I need to make anonymous some tabledata. I'd like to use hash-functions. Is there in db2, something like in oracle: DBMS_UTILITY.GET_HASH_VALUE(...)?

    Thank you very much.

    1. You can use the ENCRYPT function
    2. Create a custom defined Hash Function or a Stored Proc
    IBM Certified Database Associate, DB2 9 for LUW

  4. #4
    Join Date
    Feb 2009
    Posts
    4

    Wink

    Thank you for your answer, I wrote this function:

    CREATE FUNCTION fhatmp.hash(INSTR VARCHAR(52))
    RETURNS CHAR(52)
    DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL
    BEGIN ATOMIC
    DECLARE REVSTR, RESTSTR VARCHAR(4000) DEFAULT '';
    DECLARE LEN INT;
    DECLARE LENE INT;
    DECLARE i INT;
    declare sm int default 5;
    IF INSTR IS NULL THEN
    RETURN NULL;
    END IF;
    IF INSTR ='' THEN
    RETURN '';
    END IF;
    SET (RESTSTR, LEN, LENE) = (hex(INSTR),LENGTH(hex(INSTR)),LENGTH(rtrim(INSTR) ));
    WHILE LEN > 10 DO
    SET (REVSTR, RESTSTR, LEN)
    = (SUBSTR(RESTSTR, 1, 1),
    SUBSTR(RESTSTR, 2, LEN - 1),
    LEN - 1);
    if REVSTR='1' then
    set (sm) = (sm +3);
    end if;
    if REVSTR='2' then
    set (sm) = (sm +7);
    end if;
    if REVSTR='3' then
    set (sm) = (sm +11);
    end if;
    if REVSTR='4' then
    set (sm) = (sm +13);
    end if;
    if REVSTR='5' then
    set (sm) = (sm +17);
    end if;
    if REVSTR='6' then
    set (sm) = (sm +19);
    end if;
    if REVSTR='7' then
    set (sm) = (sm +23);
    end if;
    if REVSTR='8' then
    set (sm) = (sm +29);
    end if;
    if REVSTR='9' then
    set (sm) = (sm +31);
    end if;
    if REVSTR='0' then
    set (sm) = (sm +37);
    end if;
    if REVSTR='A' then
    set (sm) = (sm +37);
    end if;
    if REVSTR='B' then
    set (sm) = (sm +37);
    end if;
    if REVSTR='C' then
    set (sm) = (sm +37);
    end if;
    if REVSTR='D' then
    set (sm) = (sm +37);
    end if;
    if REVSTR='E' then
    set (sm) = (sm +37);
    end if;
    if REVSTR='F' then
    set (sm) = (sm +37);
    end if;
    END WHILE;
    set (i,RESTSTR)=(0, rtrim(cast(sm as char(52))));
    while (i < LENE) do
    set (i,REVSTR)=(i+1,REVSTR||RESTSTR);
    end while;
    RETURN (substr(REVSTR,1,lene));
    END

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •