ERROR 1064 (42000):
Posted by:
Xin Li
Date: February 14, 2006 12:22PM
I tried to create a stored procedure using a script below and got following error, please help. MySQL is 5.0.18.
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 'DECLARE mycount int(11);
DECLARE accountstart varchar(40);
select CONCAT(' at line 1
DROP PROCEDURE IF EXISTS astCreateAcc;
delimiter |
CREATE PROCEDURE astCreateAcc (OUT nextid varchar(40), suid int(10), stech varchar(128))
NOT DETERMINISTIC
BEGIN
DECLARE mycallerid varchar(255);
DECLARE mycount int(11);
DECLARE accountstart varchar(40);
select CONCAT(value,'%') into accountstart from astsystem where name = 'accountstart' and serverid = 'DEF';
if EXISTS (select accountcode from astaccount where accountcode like accountstart) THEN
select (max(accountcode)+1) into nextid from astaccount where accountcode like accountstart;
ELSE
SET nextid = (select value from astsystem where name = 'firstaccount' and serverid = 'DEF');
END IF;
insert into astaccount (uid,accountcode,tech,date_created, secret, mailboxpin)
values (suid, nextid, stech, Now(),RIGHT(Rand(),6),RIGHT(Rand(),4));
/* SET lastid = LAST_INSERT_ID(); */
update astaccount set callerid = nextid, mailbox = nextid where accountcode = nextid;
if EXISTS (select uid from pbx_users where uid = suid) THEN
update astaccount set callerid = (select name from pbx_users where uid = suid) where accountcode = nextid;
END IF;
if NOT EXISTS (select uid from astuser where uid = suid) THEN
insert into astuser (uid, callbackto, comment) values (suid, nextid, mycallerid);
END IF;
update astuser set lastaccount = nextid where uid = suid;
END
|
delimiter ;