0

我正在尝试创建一个存储过程,该过程将根据传递的 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;

你能帮我吗?

4

1 回答 1

0

您必须在声明日期时间的任何地方设置日期时间变量的精度。您还在 return 语句中忘记了一个“,”。

正确的程序如下所示:

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;
于 2013-09-13T09:20:39.673 回答