(原创)mysql下新建存储过程

 

创建存储过程专门处理主表中用户名信息

DELIMITER //
create procedure test1()
begin
declare i int;
set i=0;
while i<4200 do
update m_ecms_news set username=(SELECT username from m_enewsuser order by  and() limit 1) where id=i;
set i=i+1;
end while;
end//

call test1()//

drop procedure test1//

 

创建存储过程中经常出现如下状况:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'begin
declare i int;
set i=0;
while i<4200 do
update m_ecms_news set userna' at line 2

 

一般情况下,出现上面的问题原因包括:

1.  直接拷贝全部SQL语句创建存储过程,MYSQL的解析器不能很好地处理;

2. 漏掉部分符号,比如存储过程名后面一般必须加一对括号等;