首页  >  文章  >  数据库  >  mysql的第一个存储过程_MySQL

mysql的第一个存储过程_MySQL

WBOY
WBOY原创
2016-06-01 13:51:331031浏览
DELIMITER //  <br>DROP PROCEDURE IF EXISTS procedure_ngg_pic_meta//  <br>CREATE PROCEDURE procedure_ngg_pic_meta()  <br>BEGIN  <br>     declare filename varchar(250) default '' ;  /*文件名*/<br>     declare style_type varchar(250) default '' ;/*风格*/<br>     declare brand varchar(100) default '' ;  /*品牌*/<br>     declare review mediumtext default '' ;/*编辑评论*/<br>     declare pid bigint(19) DEFAULT '0' ;/*定义pid*/<br>     DECLARE rs CURSOR FOR select a.filename from tb_pictures a;/*申明游标*/<br>     declare CONTINUE HANDLER FOR SQLSTATE '02000' SET filename = null; /*当文件名为null时跳出循环*/<br>     OPEN rs;/*打开游标*/<br>     FETCH rs INTO filename;  /*取得文件名*/<br>     WHILE ( filename is not null) DO  <br>           /*开始遍历*/<br>           /*主代码开始*/<br>           select a.pid into pid from wp_ngg_pictures a where a.filename=filename;/*找到pid*/<br>           select b.style_type,b.brand,b.review into style_type,brand,review from tb_pictures b where b.filename=filename;<br>           insert into wp_nggcf_field_values (pid,fid,field_value,ngg_type,dateadded)<br>           values( pid,6,style_type,1,now());<br>        insert into wp_nggcf_field_values(pid,fid,field_value,ngg_type,dateadded)<br>        values(pid,5,brand,1,now());<br>        insert into wp_nggcf_field_values(pid,fid,field_value,ngg_type,dateadded)<br>        values(pid,7,review,1,now());<br>           /*主代码结束*/<br>           FETCH rs INTO filename ;<br>        END WHILE; /*  遍历结束*/<br>     CLOSE rs;/*关闭游标 */<br>END //  <br>DELIMITER ;
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn