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
  •  | 
  •  

Question

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

Was it helpful?

Solution

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';
.....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top