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

  • Home
  • SEARCH
  • 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 9196361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:50:03+00:00 2026-06-17T21:50:03+00:00

I want to pass in the string such as 1,3,5,7,9,0,3 which comes from a

  • 0

I want to pass in the string such as “1,3,5,7,9,0,3” which comes from a Java method into a function and for the function to return each value separated by the comma as an Int which will then be used later in a stored procedure (shown below).

CREATE PROCEDURE updateLastModifiedDate(IN p_classId VARCHAR(21844), IN p_timestamp VARCHAR(21844))
    BEGIN
        SET @query = CONCAT ('UPDATE class SET LastModifiedDate = ',p_timestamp,' WHERE ClassId IN (', p_classId ,')');
        PREPARE stmt FROM @query;
        EXECUTE stmt;
        DEALLOCATE PREPARE stmt;
    END //
DELIMITER ;

How would I write the function?

  • 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-17T21:50:04+00:00Added an answer on June 17, 2026 at 9:50 pm

    In your case, the input to the function is a COMMA SEPARATED string. But MySql does not include a built-in function to split a COMMA SEPARATED string (comma is just an example for a separator).

    You have mentioned the input as “1,3,5,7,9,0,3”. That means, the count of items is 7. This count Needs to be Constant. I can give you as example but the Count of items should be Constant always.

    Also a mysql function can return a single value only. So you have to call the Procedure from within the function only (after splitting values).

    Am giving you a mysql function with the assumption that, the input string contains 7 items always And the separator used was comma. You have have to modify the function otherwise.

    DELIMITER @@
    
    CREATE FUNCTION getCustomerFullName(commaSeparatedString VARCHAR(256))
    RETURNS INT
    BEGIN
      DECLARE value1 INT DEFAULT 0;
      DECLARE value2 INT DEFAULT 0;
      DECLARE value3 INT DEFAULT 0;
      DECLARE value4 INT DEFAULT 0;
      DECLARE value5 INT DEFAULT 0;
      DECLARE value6 INT DEFAULT 0;
      DECLARE value7 INT DEFAULT 0;
    
      IF NOT commaSeparatedString IS NULL
        THEN
              SELECT LENGTH(commaSeparatedString) - LENGTH(REPLACE(commaSeparatedString, ',', '')) INTO @commaCount;
    
              IF  @commaCount = 0
                THEN
                     RETURN 0;  
              ELSE
                SET value1 = REPLACE(SUBSTRING(SUBSTRING_INDEX(commaSeparatedString, ',', 1),LENGTH(SUBSTRING_INDEX(commaSeparatedString, ',', 0)) + 1), ',', '');
                SET value2 = REPLACE(SUBSTRING(SUBSTRING_INDEX(commaSeparatedString, ',', 2),LENGTH(SUBSTRING_INDEX(commaSeparatedString, ',', 1)) + 1), ',', '');
                SET value3 = REPLACE(SUBSTRING(SUBSTRING_INDEX(commaSeparatedString, ',', 3),LENGTH(SUBSTRING_INDEX(commaSeparatedString, ',', 2)) + 1), ',', '');
                SET value4 = REPLACE(SUBSTRING(SUBSTRING_INDEX(commaSeparatedString, ',', 4),LENGTH(SUBSTRING_INDEX(commaSeparatedString, ',', 3)) + 1), ',', '');
                SET value5 = REPLACE(SUBSTRING(SUBSTRING_INDEX(commaSeparatedString, ',', 5),LENGTH(SUBSTRING_INDEX(commaSeparatedString, ',', 4)) + 1), ',', '');
                SET value6 = REPLACE(SUBSTRING(SUBSTRING_INDEX(commaSeparatedString, ',', 6),LENGTH(SUBSTRING_INDEX(commaSeparatedString, ',', 5)) + 1), ',', '');
                SET value7 = REPLACE(SUBSTRING(SUBSTRING_INDEX(commaSeparatedString, ',', 7),LENGTH(SUBSTRING_INDEX(commaSeparatedString, ',', 6)) + 1), ',', '');
    
            END IF;
      END IF; 
    
      CALL updateLastModifiedDate(value1, value2, value3, value4, value5, value6, value7);
    
      RETURN 1;
    END;
    @@
    
    DELIMITER ;
    

    Courtesy:

    • http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#c7359
    • http://dinushasblog.blogspot.in/2010/12/split-strings-in-mysql.html
    • http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass a function call(which returns a string) as a replacement string
In JNI when we want to pass a string from C to java we
i want to pass a string from an input box that after submition automatically
I want to pass an object (not just a string or integer) from a
I want to be able to pass a string (['parent_array']['child_array']) to a function that
A function takes a string as argument, example fn(string). I want to pass different
Suppose you have a Java method void foobar(int id, String ... args) and want
I want to create a string and pass it by reference such that I
I want to have a function debug_print(fmt, args) which takes format string, arguments and
I want to pass string as a parameter in with my jni. but when

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.