2011-01-11 139 views
0

这个问题花了我近一个小时,现在我知道这很简单。MySQL存储过程声明问题

我收到以下错误:

#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

我已经整理了一个小的例子 - 注意使用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 ; 
+0

我注意到我的IN在错误的位置,然后我尝试去做分隔符但是无法使它工作,但是你的作品完美。所以我不确定我做错了什么。 谢谢! – Khirok 2011-01-11 23:19:13

0

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

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

这是问题之一。谢谢。 – Khirok 2011-01-11 23:17:48