MySQL Forums
Forum List  »  Stored Procedures

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 ;

Options: ReplyQuote


Subject
Views
Written By
Posted
ERROR 1064 (42000):
3416
February 14, 2006 12:22PM
1503
February 14, 2006 01:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.