码迷,mamicode.com
首页 > 数据库 > 详细

mysql自定义函数与过程中写法的注意事项

时间:2015-03-17 15:40:15      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

 1 BEGIN
 2     #Routine body goes here...
 3 /*
 4 update szzx_goods_common set  gc_id=i where  gc_name=(SELECT gc_name from szzx_goods_class where  gc_id=i);
 5 */
 6  DECLARE i,goodsid  int(11);
 7  declare goodsname,img  varCHAR(200);
 8  set i=104;
 9  WHILE i<1815 do
10 SELECT image_url,goods_id into img,goodsid from goods_image where image_id=i;
11 #SELECT goods_id into goodsid from ecm_goods_image where imgage_id=i;
12 SELECT goods_name into goodsname from ecm_goods where goods_id=goodsid;
13 select goods_id into goodsid from szzx_goods where goods_name=goodsname;
14 INSERT into szzx_goods_images(goods_commonid,store_id,goods_image,goods_image_sort)VALUES(goodsid,1,img,1);
15 set i=i+1;
16 
17 End WHILE;
18     RETURN 0;
19 ENd

1、在使用使用变量时先定义变量后最下面再赋值。多个变量类型一致,可以用 declare 变量名1,变量名2这样的格式。

2、在函数或过程中用select 语句给变量赋值时,格式应为:select 字段1,字段2 into 变量1,变量2 from 表名 格式

 

mysql自定义函数与过程中写法的注意事项

标签:

原文地址:http://www.cnblogs.com/fogwang/p/4344475.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!