dave101ua
dave101ua

Reputation: 191

mysql stored function return value charset

I have mysql user defined function

DELIMITER $$ 
    CREATE FUNCTION `myfunc`(`str` TEXT) RETURNS TEXT CHARSET utf8
NO SQL
DETERMINISTIC
SQL SECURITY INVOKER
BEGIN

RETURN str;
END$$

DELIMITER ;

it just returns passed parameter back without any changes

My problem is that if I pass some russian or greece letters then I get back only ?????? as response

SELECT myfunc('ывфафывавы');

will return ??????????

if I call SELECT myfunc('sdfasfsdf'); I get sdfasfsdf as result

Can't find where the prob is , any ideas ?

Upvotes: 2

Views: 6170

Answers (2)

Omkar
Omkar

Reputation: 1

Thanks for helping out others.

use RETURNS TEXT CHARSET UTF8MB4

if using it 2024 onwards.

Upvotes: 0

O. Jones
O. Jones

Reputation: 108696

Try declaring your parameter with CHARSET utf8 just as you define your result.

DELIMITER $$ 
CREATE FUNCTION `myfunc`(`str` TEXT CHARSET utf8) 
    RETURNS TEXT CHARSET utf8
    NO SQL
    DETERMINISTIC
    SQL SECURITY INVOKER
    BEGIN

        RETURN str;
    END$$

DELIMITER ;

Without that MySQL casts your incoming parameter to your default charset.

Upvotes: 6

Related Questions