0

我正在尝试创建一个 SQL 函数,该函数将采用 2 个参数并转换为请求的案例格式。我的查询是

DELIMITER $$

CREATE FUNCTION Convertcase(
    sentence VARCHAR(50),req_case VARCHAR(50)
) 
RETURNS VARCHAR(50)
DETERMINISTIC
BEGIN
DECLARE word VARCHAR(50);
IF req_case = 'upper' THEN
    SET word= UPPER(sentence);
ELSEIF req_case = 'lower' THEN
    SET word= LOWER(sentence);
RETURN (word);
END$$
DELIMITER;

convertcase('test sentence','upper')

但我得到了错误

Query : CREATE FUNCTION Convertcase(      sentence varchar(50),req_case varchar(50)  )   RETURNS VARCHAR(50)  DETERMINISTIC  BEGIN  DECL...
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 13
4

1 回答 1

0

你需要并结束如果;

drop function if exists convert_case;
DELIMITER $$
CREATE FUNCTION convert_case(sentence VARCHAR(50),req_case VARCHAR(50)) 
RETURNS VARCHAR(50)
BEGIN
DECLARE word VARCHAR(50);
IF req_case = 'upper' THEN
    SET word= UPPER(sentence);
ELSEif req_case = 'lower' THEN
    SET word= LOWER(sentence);
end if; ########
return word;
END$$
DELIMITER ;
于 2020-05-03T07:48:41.030 回答