创建过程中的MySql OUT参数未编译

时间:2014-07-27 05:31:13

标签: mysql stored-procedures out-parameters select-into

我试图编写一个MySQL存储过程,但是从表中选择后我似乎无法使用多个OUT参数进行编译。我无法找到我试图做的具体例子。编译器错误状态为"UNEXPECTED INTO, expecting ; "而且,它表示FirstName column is not declared。任何帮助将不胜感激。

 CREATE PROCEDURE `SP_SelectAllFighters`(out o_FighterID int, out o_FirstName varchar(45), out o_MiddleName varchar(45), out o_LastName varchar(45), o_FullName varchar(155), out o_WeightClass varchar(45), out o_TeamAssociation varchar(45), out o_Organization varchar(45))
BEGIN
    SELECT
        ID into o_FighterID,
        -- CONCAT_WS(' ', FirstName, MiddleName, LastName) into o_FullName,
        FirstName into o_FirstName,
        MiddleName into o_MiddleName,
        LastName into o_LastName,
        WeightClass into o_WeightClass,
        TeamAssociation into o_TeamAssociation,
        Organization into o_Organization
    FROM
        COMPETITOR;
END

1 个答案:

答案 0 :(得分:0)

我以为你可以这样做:

SELECT o_FighterID = ID,
    o_FullName = CONCAT_WS(' ', FirstName, MiddleName, LastName),
    o_FirstName = FirstName,
    etc.
FROM
    COMPETITOR;

但是在查看MySQL引用之后,看起来像Select into语法是这样的:

SELECT ID, FirstName, ... into o_FighterID, o_FirstName, ...
FROM
    COMPETITOR;

此外,如果声明您的列名未声明,您可能需要考虑使用表别名。

http://dev.mysql.com/doc/refman/5.0/en/select-into.html