Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2007

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    don't re-invent the wheel

    use LIKE | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2007
    As rudy says:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts