Mysql语法错误(mysql noob here)

时间:2011-07-04 16:58:54

标签: mysql sql mysql-error-1064

DELIMITER ||

CREATE FUNCTION InsertEvent (IN iPatientMonitoringId BIGINT, 
                             IN iTypeId SMALLINT(6), 
                             IN iChannelId SMALLINT(6), 
                             IN iStart TIMESTAMP, 
                             IN iEnd TIMESTAMP)
RETURNS BIGINT DETERMINISTIC

BEGIN

  INSERT INTO Event 
    (Id, PatientMonitoringId, TypeId, ChannelId, StartOcurrence, EndOcurrence)
  VALUES 
    ('', iPatientMonitoringId, iTypeId, iChannelId, iStart, iEnd);

  RETURN LAST_INSERT_ID();

END ||

DELIMITER ;

这个SQL查询看起来不错,但我不理解phpmyadmin返回的错误:

  

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'IN iPatientMonitoringId BIGINT,IN

附近使用正确的语法

1 个答案:

答案 0 :(得分:3)

来自:http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html

Note
Specifying a parameter as IN, OUT, or INOUT is valid only for a PROCEDURE. 
For a FUNCTION, parameters are always regarded as IN parameters.

因此,我相信你应该放弃IN。

尝试:

CREATE FUNCTION InsertEvent (iPatientMonitoringId BIGINT, iTypeId SMALLINT(6), 
iChannelId SMALLINT(6), iStart TIMESTAMP, iEnd TIMESTAMP) RETURNS BIGINT 
DETERMINISTIC