Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:18:49+00:00 2026-06-15T18:18:49+00:00

I am trying to create a MySQL function IS_IN_ENUM(‘value’, ‘val1’, ‘val2’, ‘val3’) which return

  • 0

I am trying to create a MySQL function IS_IN_ENUM('value', 'val1', 'val2', 'val3') which return true if ‘value’ is in (‘val1’, ‘val2’, ‘val3’). I know I can do SELECT 'value' IN ('val1', 'val2', 'val3') but that’s less intersting because I just want to learn how to create such functions.

I give you an example, consider the following ADD function :

CREATE FUNCTION my_add (
    a DOUBLE,
    b DOUBLE
)
RETURNS DOUBLE
BEGIN

    IF a IS NULL THEN
        SET a = 0;
    END IF;

    IF b IS NULL THEN
        SET b = 0;
    END IF;

    RETURN (a + b);
END;

If I do SELECT my_add(1, 1), I get 2 (wow!).

How can I improve this function to be able to call :

SELECT my_add(1, 1); -- 2
SELECT my_add(1, 1, 1); -- 3
SELECT my_add(1, 1, 1, 1); -- 4
SELECT my_add(1, 1, 1, 1, 1, 1, .....); -- n
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:18:51+00:00Added an answer on June 15, 2026 at 6:18 pm

    The function example you show is a Stored Function, not a UDF. Stored Functions in MySQL don’t support a variable number of arguments, as @Enzino answered.

    MySQL UDFs are written in C or C++, compiled into dynamic object files, and then linked with the MySQL server with a different syntax of CREATE FUNCTION.

    See http://dev.mysql.com/doc/refman/5.5/en/adding-udf.html for details of writing UDFs. But I don’t know if you want to get into writing C/C++ code to do this.

    MySQL UDFs do support variable number of arguments. In fact, all UDFs implicitly accept any number of arguments, and it’s up to you as the programmer to determine if the number and datatypes of the arguments given are valid for your function.

    Processing function arguments in UDFs is documented in http://dev.mysql.com/doc/refman/5.5/en/udf-arguments.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a composite key for MYSQL, but i dont know
I am using MySQL v5.1.36 and I am trying to create a stored function
I am trying to create a function in MySQL: Here is the SQL code:
I'm trying to create a MySQL function for calculating the levenshtein distance. I found
trying to create a dependant select function that fetch json value from database, but
I'm trying to create a function to return all of the users in a
I trying to create a MySql Query from the $_POST values trouble is i
I'm trying to create a mysql table from the inner join between two other
I am trying to create this table in a MySQL database CREATE TABLE IF
Im trying to create relationships between four tables in MySql: mainnodes (ID) subnodes (ID)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.