If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Hash Function

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-24-09, 07:33
Vovan Vovan is offline
Registered User
 
Join Date: Feb 2009
Posts: 4
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.
Reply With Quote
  #2 (permalink)  
Old 02-24-09, 10:08
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 3,362
There's no built-in function, but you can easily create one for yourself, as described here: datori Top 5 SQL statements
Reply With Quote
  #3 (permalink)  
Old 02-24-09, 11:48
nick.ncs nick.ncs is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 02-26-09, 02:46
Vovan Vovan is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On