User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 375,202 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,355 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1404 | Replies: 17
Reply
Join Date: Aug 2007
Posts: 141
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

UDF in MySQL

  #1  
May 8th, 2008
Hi.
I want to know how it is possible to write your own function "UDF" in MySQL? and how use that UDF in MySQL?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Posts: 141
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: UDF in MySQL

  #2  
May 9th, 2008
hi again,
any idea how to make UDF in MySQL ???
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 1,924
Reputation: peter_budo has a spectacular aura about peter_budo has a spectacular aura about peter_budo has a spectacular aura about 
Rep Power: 9
Solved Threads: 221
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Posting Virtuoso

Re: UDF in MySQL

  #3  
May 9th, 2008
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Apr 2008
Posts: 290
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 39
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: UDF in MySQL

  #4  
May 9th, 2008
hi,
MySQL does not support user defined functions (UDF) in the sense of standard SQL, which, for example, allow such a declaration in its own PSM language:
  1. CREATE FUNCTION avgg(*)
  2. returns float
  3. ap float
  4. SELECT avg(price) FROM goods INTO ap
  5. RETURN ap
  6.  
  7. -- usage
  8. SELECT id FROM goods WHERE price < avgg(*)
In MySQL kind of UDF can be defined as a plain C program. Such C-coded program must be linked dynamically, there is also special header handling. This approach is rather complicated and error prone. Once Borland's interbase had had same approach.

brs,
tesu
Reply With Quote  
Join Date: Aug 2007
Posts: 141
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: UDF in MySQL

  #5  
May 10th, 2008
Thanks for replying both...
Respected tesuji tesuji,
could you please guide me how to write a sample UDF, like Uppercase first letter in C, and then how to configure that UDF using in MySQL.

NOTE:
I know that the Ucase function exist in MySQL, but as an example for me to learn writing UDF...

Thanks
Reply With Quote  
Join Date: Apr 2008
Posts: 290
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 39
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: UDF in MySQL

  #6  
May 10th, 2008
well tanha,
though i ve written UDFs for Sybase Databases a good many times, it s rather time-consuming doing that within MySQL. You may have a look at
http://dev.mysql.com/doc/refman/5.0/en/adding-udf.html
to get an impression of the hard work to be done for it (as opposed to the convenient way when programming UDF by using SQL1999 standards).
krs,
tesu
Reply With Quote  
Join Date: Apr 2008
Posts: 290
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 39
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: UDF in MySQL

  #7  
May 10th, 2008
Here is an UDF example which runs on SQL Anywhere 9:
  1. CREATE FUNCTION upperFirstChar(IN isc VARCHAR(1000))
  2. RETURNS VARCHAR(1000)
  3. /* Usage:
  4.   select upperFirstChar('hello!') AS 'Capitalized 1st Character';
  5.   Result:
  6.   Capitalized 1st Character
  7.   -------------------------
  8.   Hello!
  9. */
  10. BEGIN
  11. DECLARE rtc VARCHAR(1000);
  12. SELECT UPPER(SUBSTRING(isc, 1, 1)) + LOWER(SUBSTRING(isc, 2,
  13. LENGTH(isc)-1)) INTO rtc;
  14. RETURN rtc;
  15. END;
I use select upper(substring(... to capitalize first char. You can also use this select within MySQL because all char functions are also available there.
Reply With Quote  
Join Date: Aug 2007
Posts: 141
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: UDF in MySQL

  #8  
May 14th, 2008
Hi tesuji,
Hope doing fine, I tried much, but still I am lost how to write UDF for MySQL, I don't like to write complex function now, I need just one sample example written in C/C++, and then use that in MySQL working...

I need this example and guide as my start point...

Therefore kindly request you, if possible post here a sample UDF written in C, and then the steps how to use of that in MySQL...
That would be very kind of you...
Thanks
Last edited by tanha : May 14th, 2008 at 1:15 pm.
Reply With Quote  
Join Date: Aug 2007
Posts: 141
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: UDF in MySQL

  #9  
May 28th, 2008
Hi, Hi, Hiiiiiiiiiiiiiiiiiiiiiiii everyone,

to be honest I studied much, but still I dont know how to create UDF in MySQL, so there should be some one did this for him/her self, plz any idea ???
Reply With Quote  
Join Date: Aug 2007
Posts: 141
Reputation: tanha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tanha tanha is offline Offline
Junior Poster

Re: UDF in MySQL

  #10  
May 29th, 2008
Just I need a simple UDF in MySQL something like uppercase firstletter ...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Other Threads in the MySQL Forum

All times are GMT -4. The time now is 2:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC