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 6826943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:12:28+00:00 2026-05-26T22:12:28+00:00

I need to construct a single transaction / stored procedure that takes in two

  • 0

I need to construct a single transaction / stored procedure that takes in two lists of foreign keys and inserts new rows into a table from those foreign keys.

Specifically, I have a table that has order_ids and item_ids corresponding to the order. I need to add to this table when orders are submitted.

To summarize in code, I would like to do:

DELIMITER ##
BEGIN
CREATE STORED PROCEDURE addOrder(IN itemIds VARCHAR(255), IN orderIds VARCHAR(255))
// ----- SQL Equivalent of -----
// for (int i = 0; i < itemIds.length; ++i)
// INSERT INTO Items_Ordered(item_id, order_id) VALUES(itemIds[i], order_ids[i]);
// -----------------------------
END ##
DELIMITER ;

So in Java, I could then just do something like:

String listOfItems = '1, 2, 6, 7, 8';
String listOfOrders = '2, 1, 99, 82, 7';
PreparedStatement ps = connection.prepareCall("CALL addOrder(" + listOfItems + ", " + listOfOrders + ")");
ps.executeUpdate();

Any ideas?

EDIT #1:

I really, really, really don’t like this hacky solution: Pass array into a stored procedure

EDIT #2:

Another solution I was thinking was to create a temporary table in the stored procedure with the input, but I don’t know how to do that either.

  • 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-05-26T22:12:28+00:00Added an answer on May 26, 2026 at 10:12 pm

    Create a string split function along these lines:

    http://kedar.nitty-witty.com/blog/mysql-stored-procedure-split-delimited-string-into-rows

    Then you can split your comma separated string into discreet values for insertion.

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

Sidebar

Related Questions

Often I just need to get a single value from MySQL that I know
In need to construct System.Single values (= IEEE 754 single precision 32-bit floats) from
I've got two tables that need to be joined via LINQ, but they live
Say I need a new type in my application, that consists of a std::vector<int>
This has been driving me crazy. I need to construct a single regex expression
I need to construct some rather simple SQL, I suppose, but as it's a
I need to construct the URL of a page in a String, to send
I need to construct a long string with javascript. Thats how i tried to
I need to construct an if statement from the data coming from the client
Currently i need to construct and update large xml files. So what is the

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.