创建过程Informix提供语法错误

时间:2013-09-12 09:56:23

标签: sql stored-procedures syntax informix

我试图创建一个存储过程,它将根据传递的ID返回相关记录。基于研究,我找到了一些东西,这使我成为了这样的存储过程:

CREATE PROCEDURE procMessageMembershipSelect1 (membershipnumber char(10))
RETURNING CHAR(10) AS membership_number, SMALLINT as message_id , varchar(200) as 
message, CHAR(1) AS target, DATETIME as date_time_creation, DATETIME as 
date_time_display;
DEFINE rsMembershipNumber CHAR(10);
DEFINE rsMessageID smallint;
DEFINE rsMessage VARCHAR(200);
DEFINE rsTarget CHAR(1);
DEFINE rsDateTimeCreation datetime;
DEFINE rsDateTimeDisplay datetime;
FOREACH
SELECT membership_number, message_id, message, target,date_time_creation, 
date_time_display
INTO rsMembershipNumber, rsMessageID, rsMessage, rsTarget, rsDateTimeCreation, 
rsDateTimeDisplay
FROM MessageMembership
WHERE membership_number = membershipnumber    
ORDER BY date_time_display
RETURN rsMembershipNumber, rsMessageID rsMessage, rsTarget, rsDateTimeCreation,   
rsDateTimeDisplay WITH RESUME;
END FOREACH
END PROCEDURE;

你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

您必须在声明日期时间的任何位置设置日期时间变量的精度。 你还在回复陈述中忘记了','。

正确的程序如下:

CREATE PROCEDURE procMessageMembershipSelect1 (membershipnumber char(10))
RETURNING CHAR(10) AS membership_number, SMALLINT as message_id , varchar(200) as 
message, CHAR(1) AS target, DATETIME year to fraction as date_time_creation, DATETIME          year to fraction as 
date_time_display;
DEFINE rsMembershipNumber CHAR(10);
DEFINE rsMessageID smallint;
DEFINE rsMessage VARCHAR(200);
DEFINE rsTarget CHAR(1);
DEFINE rsDateTimeCreation datetime year to fraction;
DEFINE rsDateTimeDisplay datetime year to fraction;
FOREACH
SELECT membership_number, message_id, message, target,date_time_creation, 
date_time_display
INTO rsMembershipNumber, rsMessageID, rsMessage, rsTarget, rsDateTimeCreation, 
rsDateTimeDisplay
FROM MessageMembership
WHERE membership_number = membershipnumber    
ORDER BY date_time_display
RETURN rsMembershipNumber, rsMessageID, rsMessage, rsTarget, rsDateTimeCreation,   
rsDateTimeDisplay WITH RESUME;
END FOREACH
END PROCEDURE;