如何在MySQL存储过程中存储和迭代结果集?

时间:2022-03-01 02:06:22

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:

我对MySQL存储过程比较陌生,所以我希望有人可以帮助我。我想调用我的存储过程(也许传入一个IN参数)并让它执行以下操作:

  1. SELECT some data
  2. 选择一些数据
  3. Iterate over the records
  4. 迭代记录
  5. Perform some operations on a few of the fields in each record including some INSERTs in other tables based on the data it finds.
  6. 对每个记录中的一些字段执行一些操作,包括基于其找到的数据在其他表中的一些INSERT。

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?

我的问题是我不知道如何存储SELECT数据集并迭代记录。我知道如何声明和设置像int和text这样的东西,但不知道完整的数据集。我该怎么做呢?

Thanks

谢谢

1 个解决方案

#1


9  

Look into MySql Cursors

查看MySql游标

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

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

#1


9  

Look into MySql Cursors

查看MySql游标

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

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