MySQL Forums
Forum List  »  Newbie

INSERT Loop
Posted by: Matthew Moser
Date: May 12, 2006 03:03PM

I need to loop over an insert X times. Where X is a variable passed in to my stored procedure. How would I go about this???


DROP PROCEDURE IF EXISTS ADD_ITEMS_TO_SALE;
CREATE PROCEDURE ADD_X_ITEMS (
IN iCode VARCHAR(45),
IN iSaleid VARCHAR(45),
IN iQuantity INTEGER
)
BEGIN
x = 1
LOOP WHILE x < iQuantity
INSERT INTO items_table(ITEM_CODE, ITEM_DESC, ITEM_PRICE, SaleID)
SELECT UPC, Name, Price, iSaleid
FROM inventory
WHERE UPC = iCode;
x = x + 1
END LOOP
END;

Now I know that the loop syntax above is not proper SQL Syntax but I have not seen any good examples, so that's what I need to know.

Thanks in advance.

Options: ReplyQuote


Subject
Written By
Posted
INSERT Loop
May 12, 2006 03:03PM
May 12, 2006 03:13PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.