how to use stored functions mysql (Error Code: 1054 Unknown column 'Right Index' in 'field list')

StackOverflow https://stackoverflow.com/questions/19213585

  •  30-06-2022
  •  | 
  •  

문제

how to use stored functions 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);

Error Code: 1054 Unknown column 'Right Index' in 'field list

도움이 되었습니까?

해결책

if you are setting a string literal in a variable, you should use single quote and not backtick -- they are used for identifiers such as table name, column names, etc...

CASE finger_id
WHEN 1 THEN
    SET NAME= 'Right Thumb';
WHEN 2 THEN
    SET NAME='Right Index';
.....
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top