Jason
Jason

Reputation: 52523

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

Upvotes: 14

Views: 21455

Answers (1)

The Scrum Meister
The Scrum Meister

Reputation: 30111

Look into MySql Cursors

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

Upvotes: 10

Related Questions