Maison > Article > base de données > mysql的第一个存储过程_MySQL
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 ;