如何使用存储函数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'字段列表
中的未知列'右索引'答案 0 :(得分:3)
如果要在变量中设置字符串文字,则应使用single quote
而不是backtick
- 它们用于表名,列名等标识符......
CASE finger_id
WHEN 1 THEN
SET NAME= 'Right Thumb';
WHEN 2 THEN
SET NAME='Right Index';
.....