簡體   English   中英

MySQL存儲過程聲明問題

[英]MySQL Stored Procedure Declare Issue

現在,這個問題使我花費了將近一個小時,而且我知道這很簡單。

我收到以下錯誤:

#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。

有人能在其中看到任何錯誤嗎?

我已經整理了一下您的示例-請注意在參數中使用定界符!

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 ;

顛倒IN和參數名稱的順序。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM