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 > MySQL > User Defined String Comparison Function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-24-07, 14:04
ozzii ozzii is offline
Registered User
 
Join Date: Mar 2007
Posts: 194
User Defined String Comparison Function

Does any body know how to create a user defined function in mysql that would achieve the following:

select id from sometable where a_fuction(some_field, 'some string') = 1;

a_fuction is the user defined function name
some_field is the field which needs to be searched
'some string' is user provided search string which needs to be searched

Basicaly what would the internal query of this fuction consist of to search a user provided search string and produce a boolean 0 or 1
Reply With Quote
  #2 (permalink)  
Old 07-24-07, 14:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
don't re-invent the wheel

use LIKE

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 07-25-07, 10:07
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
As rudy says:
Quote:
don't re-invent the wheel
However, should you wish to do it you can use a CREATE FUNCTION in MySQL 5+ to take the field name and string and produce a returned result based on whether it exists or not.
I doubt that'll you'll be able to be able to write a better algorithm than already exists. That and you won't be able to use indexes like MySQL's internal procedures will, but by all means give it a go and let us know how you get on.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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