文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>mysql游标使用经典实例2

mysql游标使用经典实例2

时间:2009-05-25  来源:sss0213

DELIMITER $$

DROP PROCEDURE IF EXISTS `testdb`.`test` $$
CREATE PROCEDURE `test`(in cprdt1 varchar(30))
BEGIN
  DECLARE done INT DEFAULT 0;
  declare done1 INT DEFAULT 0;
  declare tprdt varchar(200);
  declare prdt1 varchar(30) ;
  declare prdt2 varchar(30);
  declare inta int;

  declare curbom cursor for select prdt from sto_boms where flag='1'  and cprdt =prdt1;
  declare curbom2 cursor for select prdt from sto_boms where flag='1' and cprdt =prdt2;
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1, done1 = 1;

  set tprdt="(";
  set inta=0;
  set prdt1=cprdt1;

  open    curbom;
  fetch   curbom into prdt1;
  while done=0 do
      if prdt1<>"" then
         set tprdt=concat(tprdt,"'",prdt1,"',");
         set prdt2=prdt1;
      end if  ;

      /*open    curbom2;
      fetch   curbom2 into prdt2;
      while done1=0 do
      if prdt2<>"" then
         set tprdt=concat(tprdt,"'",prdt2,"',");
      end if  ;
      fetch   curbom2 into prdt2;
      end while;
      close curbom2;    */

  fetch   curbom into prdt1;
  end while;
  close curbom;

   set tprdt=concat(tprdt,")");
   select tprdt;
END $$

DELIMITER ;

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载