-1

如何使用存储函数mysql

drop function if exists finger_name;
DELIMITER \\
CREATE DEFINER=`root`@`localhost` FUNCTION `finger_name`(finger_id INT) 
RETURNS `VARCHAR`(45) CHARSET `utf8`
BEGIN
DECLARE NAME `varchar`(45);
CASE finger_id
    WHEN 1 THEN
SET NAME= `Right Thumb`;
    WHEN 2 THEN
SET NAME= `Right Index`;
    WHEN 3 THEN
SET NAME= `Right Middle`;
ELSE
SET NAME= `Not Registered`;
END CASE;
RETURN NAME;
END\\ 
delimiter ;

SELECT FINGER_NAME(2);

错误代码:1054 '字段列表中的未知列'右索引'

4

1 回答 1

3

如果您在变量中设置字符串文字,您应该使用single quote而不是backtick- 它们用于标识符,例如表名,列名等......

CASE finger_id
WHEN 1 THEN
    SET NAME= 'Right Thumb';
WHEN 2 THEN
    SET NAME='Right Index';
.....
于 2013-10-06T20:29:22.953 回答