首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL存储过程Declare问题

MySQL存储过程Declare问题
EN

Stack Overflow用户
提问于 2011-01-12 06:43:52
回答 2查看 5.5K关注 0票数 0

这个问题现在已经花了我将近一个小时,我知道这是很简单的事情。

我收到以下错误:

代码语言:javascript
复制
#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

下面是我的查询,它看起来很正确:

代码语言:javascript
复制
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。

有人能看出这里面有什么不对劲吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-01-12 06:53:37

我整理了一下你的例子--注意分隔符和参数的用法!

代码语言:javascript
复制
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 ;
票数 2
EN

Stack Overflow用户

发布于 2011-01-12 06:49:03

颠倒IN和参数名称的顺序。

代码语言:javascript
复制
...(IN hl7PatientName VARCHAR(256), IN hl7PatientId VARCHAR(256))...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4663533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档