MySQL存储过程声明问题

时间:2011-01-11 22:43:52

标签: mysql stored-procedures

这个问题花了我差不多一个小时了,我知道这很简单。

我收到以下错误:

#1064 - 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 'IN VARCHAR(256), hl7PatientId IN VARCHAR(256))
BEGIN

DECLARE mainQueue INT' at line 1

以下是我的查询:

DROP PROCEDURE IF EXISTS insert_data;

CREATE PROCEDURE `insert_data`(hl7PatientName IN VARCHAR(256), hl7PatientId IN VARCHAR(256))
BEGIN

DECLARE mainQueue INT DEFAULT 1;

SELECT `queueid` INTO mainQueue FROM `queues` WHERE `description` LIKE 'Main' AND `enabled` = 1 LIMIT 1;

INSERT INTO `queue_data`
(`queueid`, `patientname`, `patientid`, `location`, `creationtime`, `priority`)
VALUES
(mainQueue, hl7PatientName, hl7PatientId, 'QUEUE_NUMBER', TIMESTAMP(), '');

END;

我正在使用MySQL 5.0.77。

任何人都可以在这看到任何错误吗?

2 个答案:

答案 0 :(得分:2)

我已经整理了一下你的例子 - 注意使用分隔符和params!

drop procedure if exists insert_queue_data;

delimiter #

create procedure insert_queue_data
(
in p_patientname varchar(255), -- size ? i always prefix my params p_ and keep the same name as the db field
in p_patientid varchar(255) -- size ? are you sure this isnt an integer ?
)
begin

-- i always prefix my variables v_ and keep same name as the db field

declare v_queueid int unsigned default 1;

select queueid into v_queueid from queues where
 description like 'Main' and enabled = 1 limit 1;

insert into queue_data(queueid, patientname, patientid, location, creationtime, priority) values
 (v_queueid, p_patientname, p_patientid, 'QUEUE_NUMBER', now(), '');

end#

delimiter ;

答案 1 :(得分:0)

反转IN和参数名称的顺序。

...(IN hl7PatientName VARCHAR(256), IN hl7PatientId VARCHAR(256))...