首頁 >資料庫 >mysql教程 >mysql的第一个存储过程_MySQL

mysql的第一个存储过程_MySQL

WBOY
WBOY原創
2016-06-01 13:51:331054瀏覽
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