Unix Technical Forum

Want to write a standard user defined function in the db2

This is a discussion on Want to write a standard user defined function in the db2 within the DB2 forums, part of the Database Server Software category; --> Knut Stolze wrote: > Maroon wrote: > > >>Hava you worked other database( Mysql ) before? I mentioned a ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 02-27-2008, 05:22 AM
Serge Rielau
 
Posts: n/a
Default Re: Want to write a standard user defined function in the db2

Knut Stolze wrote:
> Maroon wrote:
>
>
>>Hava you worked other database( Mysql ) before? I mentioned a example.
>>Anyway.
>> concat_ws add the string that are given to its parameter.

>
>
> That's done by the CONCAT (or ||) operator in the SQL standard and also DB2.
> So that is already covered.
>
>
>> and md5 will implement a algoritham like ssh

>
>
> I think you're mixing up encryption, hash algorithms and network protocols.
> md5() is a function that "Calculates an MD5 128-bit checksum for the
> string." (according to the MySQL manual).
>
>
> I believe the biggest issue here is to understand that functions have
> nothing to do with tables per se. A function takes a set of input values
> and returns an output value. Period.
>
> In the original query, the function CONCAT_WS takes the two strings of the
> current row in the "student" table and concatenates them to a single
> string. That string is now passed to the MD5 function, which calculates
> the MD5 checksum (a hash value basically).
> Porting this to DB2 requires that you implement a function which takes a
> string as input and returns the string's checksum. Register that function
> (or Java method) as UDF, and off you go.
>

Look for this thread:
"Have any function in the DB2 database that can generate unique id for
each String?"
I posted a hash function on Oct 17 in this forum.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 02-27-2008, 05:23 AM
Maroon
 
Posts: n/a
Default Re: Want to write a standard user defined function in the db2

Knut,
Thanks for your kind reply.

> In the original query, the function CONCAT_WS takes the two strings of the
> current row in the "student" table and concatenates them to a single
> string.

How can i access the current rows in the CONCAT_WS function?
if the table is student and data is in the following:-
roll name
1 A
2 B
3 C

select roll, md5(concat_ws("roll","name")) from student.

for the concat_ws--->The output will be

1 1A
2 2A
3 3C

How can i find the current rows in my user defined function?

I am looking forward for ur kind reply.



Knut Stolze wrote:
> Maroon wrote:
>
> > Hava you worked other database( Mysql ) before? I mentioned a example.
> > Anyway.
> > concat_ws add the string that are given to its parameter.

>
> That's done by the CONCAT (or ||) operator in the SQL standard and also DB2.
> So that is already covered.
>
> > and md5 will implement a algoritham like ssh

>
> I think you're mixing up encryption, hash algorithms and network protocols.
> md5() is a function that "Calculates an MD5 128-bit checksum for the
> string." (according to the MySQL manual).
>
>
> I believe the biggest issue here is to understand that functions have
> nothing to do with tables per se. A function takes a set of input values
> and returns an output value. Period.
>
> In the original query, the function CONCAT_WS takes the two strings of the
> current row in the "student" table and concatenates them to a single
> string. That string is now passed to the MD5 function, which calculates
> the MD5 checksum (a hash value basically).
> Porting this to DB2 requires that you implement a function which takes a
> string as input and returns the string's checksum. Register that function
> (or Java method) as UDF, and off you go.
>
> --
> Knut Stolze
> DB2 Information Integration Development
> IBM Germany


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 02-27-2008, 05:23 AM
Knut Stolze
 
Posts: n/a
Default Re: Want to write a standard user defined function in the db2

Maroon wrote:

> Knut,
> Thanks for your kind reply.
>
>> In the original query, the function CONCAT_WS takes the two strings of
>> the
>> current row in the "student" table and concatenates them to a single
>> string.

> How can i access the current rows in the CONCAT_WS function?


That's the thing: you don't access the row from the function but rather the
values of the columns of the current row are passed to the function. You
just have it backwards!

> if the table is student and data is in the following:-
> roll name
> 1 A
> 2 B
> 3 C
>
> select roll, md5(concat_ws("roll","name")) from student.
>
> for the concat_ws--->The output will be
>
> 1 1A
> 2 2A
> 3 3C
>
> How can i find the current rows in my user defined function?


What would you need that rows for. The function is called 3 times, once for
each row. The first call gets the concatenation of "1" and "A" as input,
calculates the MD5 checksum and return that value. The second call gets
"2" and "B" as input, and the third gets "3" and "C" - just like functions
work in pretty much all other programming languages.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 02-27-2008, 05:23 AM
Maroon
 
Posts: n/a
Default Re: Want to write a standard user defined function in the db2

Knut
Thanks

Maroon
www.jence.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:31 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com