In know MySQL (MariaDB) functions and the case statement but how to combine the two? I'm implementing a TO_STR translate function where I don't want to pollute the database with addtional tables. This is what I tried:
CREATE FUNCTION CODE_TO_STR(CODE CHAR(4)) RETURNS VARCHAR(50) AS
BEGIN
RETURN SELECT
CASE CODE
WHEN '1' THEN 'Code is one'
WHEN '2' THEN 'Code is two'
ELSE CODE
END;
END;
which gives an 1064 error.
EDIT: corrected the error RETURN->RETURNS
EDIT:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT CASE CODE WHEN '1' THEN 'Code is one' WHEN '2' THEN 'Code is two...' at line 3 0.000 sec
The
SELECTis superfluous. the correctCREATEshould be: