Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store and iterate over a result set in a MySQL Stored Proc?

I'm relatively new to MySQL stored procs, so I was hoping someone could help me out here. I want to call my stored proc (maybe pass in one IN param) and have it do the following:

  1. SELECT some data
  2. Iterate over the records
  3. Perform some operations on a few of the fields in each record including some INSERTs in other tables based on the data it finds.

My problem is that I don't know how to store the SELECT data set and iterate the records. I know how to declare and set stuff like int and text, but not full data sets. How do I do this?

Thanks

like image 330
Jason Avatar asked Feb 01 '11 22:02

Jason


1 Answers

Look into MySql Cursors

http://dev.mysql.com/doc/refman/5.0/en/cursors.html

like image 68
The Scrum Meister Avatar answered Oct 01 '22 06:10

The Scrum Meister