473,396 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Have any function in the DB2 database that can generate unique id for each String?

Hello,
Have any function in the DB2 database that can generate unique id
for each string like oracle, mysql,sybase,sqlserver database.

In mysql:-
select md5(concat_ws("Row name")) from tablename;

Here this function generate unique id for each row of the table.

Regards..
..Mamun

Nov 12 '05 #1
10 18533
To generate a unique string use the appropriately named GENERATE_UNIQUE
function.

<Ma*******@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
Hello,
Have any function in the DB2 database that can generate unique id
for each string like oracle, mysql,sybase,sqlserver database.

In mysql:-
select md5(concat_ws("Row name")) from tablename;

Here this function generate unique id for each row of the table.

Regards..
..Mamun

Nov 12 '05 #2


If i use generate_unique() then there is no output. On the other hand
if i use generate_unique("dsf") then error generate.
Will you tell me how can i use it with an example Please?

Mark Yudkin wrote:
To generate a unique string use the appropriately named GENERATE_UNIQUE
function.

<Ma*******@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
Hello,
Have any function in the DB2 database that can generate unique id
for each string like oracle, mysql,sybase,sqlserver database.

In mysql:-
select md5(concat_ws("Row name")) from tablename;

Here this function generate unique id for each row of the table.

Regards..
..Mamun


Nov 12 '05 #3
What is the name of such function in Oracle or MS SQL Server?
Oracle have psuedocolumns like ROWID, ROWNUM. But, these are not
function and take no parameter.

Nov 12 '05 #4
Please use the information center on the web as a resource:

http://publib.boulder.ibm.com/infoce...help/index.jsp

Entering GENERATE_UNIQUE in the search area you should find the first entry
gives you the description, syntax and examples of its use.

Bob

"Mamun" <Ma*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...


If i use generate_unique() then there is no output. On the other hand
if i use generate_unique("dsf") then error generate.
Will you tell me how can i use it with an example Please?

Mark Yudkin wrote:
To generate a unique string use the appropriately named GENERATE_UNIQUE
function.

<Ma*******@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
Hello,
Have any function in the DB2 database that can generate unique id
for each string like oracle, mysql,sybase,sqlserver database.

In mysql:-
select md5(concat_ws("Row name")) from tablename;

Here this function generate unique id for each row of the table.

Regards..
..Mamun

Nov 12 '05 #5
Is Oracle claiming that md5 will generate a unique id? I hope not since
it's not true.

MD5 (Message Digest 5) is a hash algorthm, much like a CRC, or any other
checksum. It can not guarentee that the number generated is a unique value,
only that it is the hash associated with the object that the checksum is
generated on. But it is entirely possible that the same hash value can be
generated from a different string.

There are many such hashes. While md5 was in use and popular for quite some
time, it has been proven to have some weaknesses and has been somewhat
replaced by the sha-1 algorthm.

If you want, you can get a whole bunch of encryption and hash routines from
www.opensssl.org, including md5, md2, sha1, etc. These routines can then
be implemented in your client code, or in the server as a fenced routine.

My personal thought is that encryption and hashing is best done in the
client code rather than in the server because of the overhead associated
with either encryption or hashing. If I have 1000 client programs attached
to a single server, I'd rather the server spend it's time getting data to me
and then have each of the 1000 client programs responsible for any hash
logic.

BTW - I'm not a java programmer, but I think that java has both md5 and
sha-1 included in the builtin security package.

M.P.
<Ma*******@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
Hello,
Have any function in the DB2 database that can generate unique id
for each string like oracle, mysql,sybase,sqlserver database.

In mysql:-
select md5(concat_ws("Row name")) from tablename;

Here this function generate unique id for each row of the table.

Regards..
..Mamun

Nov 12 '05 #6
The name of the hash function in the oracle database is
dbms_utility.get_hash_value(). I am looking like this in the db2
database.
..Mamun
Tonkuma wrote:
What is the name of such function in Oracle or MS SQL Server?
Oracle have psuedocolumns like ROWID, ROWNUM. But, these are not
function and take no parameter.


Nov 12 '05 #7
Please review the documentation.

I wonder if your question is for an MD5 hash function? Since you asked about
"generate a unique id", MD5 is a hash function and not a unique string
generator, and SQL Server (I don't know MySQL and I haven't used Sybase
since V9) doesn't have an MD5 function, I had assumed not. Otherwise, try
asking your question clearly and without inconsistencies and contradictions,
so that we don't have to guess what you're asking.

"Mamun" <Ma*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...


If i use generate_unique() then there is no output. On the other hand
if i use generate_unique("dsf") then error generate.
Will you tell me how can i use it with an example Please?

Mark Yudkin wrote:
To generate a unique string use the appropriately named GENERATE_UNIQUE
function.

<Ma*******@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
> Hello,
> Have any function in the DB2 database that can generate unique id
> for each string like oracle, mysql,sybase,sqlserver database.
>
> In mysql:-
> select md5(concat_ws("Row name")) from tablename;
>
> Here this function generate unique id for each row of the table.
>
> Regards..
> ..Mamun
>

Nov 12 '05 #8
Hello Mark Yuddin,
I am sorry that u feel bothering. But i
gave an example and my wanted was have any function in DB2 database
that can generate unique value or id for each string? If it fall u in
heavy contradiction, i am sorry, Any way i could not find my answer. If
u know Please help me.

Nov 12 '05 #9
Mamun wrote:
Hello Mark Yuddin,
I am sorry that u feel bothering. But i
gave an example and my wanted was have any function in DB2 database
that can generate unique value or id for each string?
The point is that a hash function does _not_ generate unique numbers/values
for a give string. You might want to read up on the basics of hash
techniques and in particular about collisions.
If it fall u in
heavy contradiction, i am sorry, Any way i could not find my answer. If
u know Please help me.


You might want to explain what exactly you did so that GENERATE_UNIQUE did
not "produce any output". It shows this for me:

$ db2 "values generate_unique()"

1
-----------------------------
x'20051017115326287128000000'

1 record(s) selected.
I also assume that you actually want a function that takes a given text as
input and generates the MD5 check sum (according to your example).

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Nov 12 '05 #10
Mamun wrote:
Hello Mark Yuddin,
I am sorry that u feel bothering. But i
gave an example and my wanted was have any function in DB2 database
that can generate unique value or id for each string? If it fall u in
heavy contradiction, i am sorry, Any way i could not find my answer. If
u know Please help me.

You are not bothering us, it's just very unclear what you are trying to
achieve.
Anyway copy the files below into sqllib\samples\c,
then, from sqllib\samples\c run: bldrtn hash
Make sure sqllib\function contains hash.dll or hash (depending on your
operating system) afterwards.
Execute the sql file and you're ready to go. If you don't have a
C-Compiler on any machine (you can copy the binary from development to
production) you can do the same in Java or define an SQL Function with
similar logic.
Keep in mind though that there is no such thing as a UNIQUE mapping
between a string of non trivial length and an INTEGER.
The space of strings has 2^(8 * (length)) elements, whie integer only
has 2^32 numbers. So beyond 4 characters it ain't gonna happen.

------------
hash.sql:
-- HASH function
DROP FUNCTION HASH;
CREATE FUNCTION HASH
(HASH VARCHAR(32000) FOR BIT DATA)
RETURNS INTEGER
SPECIFIC HASH EXTERNAL NAME 'hash!hash'
NOT FENCED RETURNS NULL ON NULL INPUT
DETERMINISTIC NO SQL NO EXTERNAL ACTION
LANGUAGE C PARAMETER STYLE SQL ALLOW PARALLEL;

-------------
hash.c:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sqlca.h>
#include <sqludf.h>

#ifdef __cplusplus
extern "C"
#endif
void SQL_API_FN hash(SQLUDF_VARCHAR_FBD *str,
SQLUDF_INTEGER *outHash,
SQLUDF_SMALLINT *strNullInd,
SQLUDF_SMALLINT *outHashNullInd,
SQLUDF_TRAIL_ARGS)
{
int i;
if (*strNullInd == -1)
{
*outHashNullInd = -1;
}
else
{
for (*outHash = 0, i = 0;
i < str->length / sizeof(SQLUDF_INTEGER);
*outHash ^= ((SQLUDF_INTEGER *) str->data)[i++])
{ /* empty */ }
i *= 4;
switch (str->length % sizeof(SQLUDF_INTEGER))
{
case 3: *outHash ^= ((SQLUDF_INTEGER) str->data[i++]);
case 2: *outHash ^= ((SQLUDF_INTEGER) str->data[i++]) << 8;
case 1: *outHash ^= ((SQLUDF_INTEGER) str->data[i]) << 16;
default : { /* empty */ }
}
*outHashNullInd = 0;
}
}
--------------
# For Unix and Linux
hash.exp:
hash
----------
# For Windows
hash.def
LIBRARY HASH
DESCRIPTION 'Library for DB2 Hash UDF'
EXPORTS
hash

-----------
db2 => values hash('');

1
-----------
0

1 record(s) selected.

db2 => values hash('a');

1
-----------
6356992

1 record(s) selected.

db2 => values hash('b');

1
-----------
6422528

1 record(s) selected.

db2 => values hash('ab');

1
-----------
6447360

1 record(s) selected.

db2 => values hash('abc');

1
-----------
6513249

1 record(s) selected.

db2 => values hash('abcd');

1
-----------
1684234849

1 record(s) selected.

db2 => values hash('abcde');

1
-----------
1678140001

1 record(s) selected.

db2 => values hash('abcdef');

1
-----------
1678051169

1 record(s) selected.

db2 => values hash('abcdefg');

1
-----------
1677984772

1 record(s) selected.
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mullin | last post by:
I need to generate a unique no. in the format like yyyymmddxxxxxx (xxxxxx 6-digitl running number) I think of create a table with two columns date value 20050405 120 20050406 99...
1
by: hikums | last post by:
I am posting this here, just in case anyone may need this. Step 1: CREATE SEQUENCE ID_SEQ START WITH 1050000 INCREMENT BY 1 MAXVALUE 9999999 NO CYCLE NO CACHE ORDER
2
by: Juan | last post by:
Hi How to generate an unique random string of determinate characters length? Thanks
28
by: Nina | last post by:
I need to generate unique id for my application. Use system time to create id, which is the best fit, but I don't know how to do it. Please help. Thanks in advance for any input.
9
by: Robert Mago | last post by:
Is there a way to create a 10 characthers or less, alph-numeric string which is unique. I can't use the guid since its longer then 10 characthers. Also i cannot use a random number, since being...
15
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code...
1
by: situ | last post by:
Hi, I'm using DB2 V9 for windows I'm inserting records into DGTT from select statement; the problem is how to insert unique value for every row inserted. I tried using “generated always as”...
6
by: er | last post by:
hi, here's why i'm trying to do: header1.hpp namespace{ struct A{};} struct B1{ A a; }; header2.hpp namespace{ struct A{};}
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.