MySQL 函数用一个 select 声明 2 个变量

MySQL function declare 2 variables with one select

我想知道如何创建一个 MySQL 函数,该函数使用 1 个 select 语句声明 2 个变量。 像这样:

CREATE FUNCTION  `inHashtagCampaign` (campaignId INT,startDateTime DATETIME,endDateTime DATETIME)
RETURNS TEXT
LANGUAGE SQL
DETERMINISTIC
BEGIN 
    DECLARE result TEXT;
    DECLARE limit BIGINT(11); 
    DECLARE suspended TINYINT(1);
    #
    #I don't know how to do this, but I'd like to use the result of this query:
    #
    result = SELECT `limit`,`suspended` FROM `settings` WHERE `campaignId` = 2;
    limit = result.limit;
    suspended = result.suspended;
END;

我知道这个功能还远未完成,但我已经有点卡在这件事上了。

我想你想做的是这样的

DECLARE @limit BIGINT(11); 
DECLARE @suspended TINYINT(1);

SELECT @limit := `limit`, @suspended := `suspended` FROM `settings` 
WHERE `campaignId` = 2;

(或)

DECLARE limit1 BIGINT(11); 
DECLARE suspended1 TINYINT(1);

SELECT `limit`,`suspended` into limit1, suspended1
FROM `settings` WHERE `campaignId` = 2;