Clemens Valiente
Clemens Valiente

Reputation: 867

Creating a stored procedure with utf8 strings

I have a stored procedure with some Cyrillic strings inside. I want to check a table with a char column if the column contains some specific strings, some of them in Cyrillic. The problem seems to be that I cannot create the procedure with those strings.

SET NAMES utf8;

delimiter //
drop procedure if exists testutf8
//
create procedure testutf8()
begin
    select 'ξενοδοχια';
end
//
delimiter ;


call testutf8();

Returns ?????????

show create procedure testutf8;

returns

Procedure testutf8

sql_mode STRICT_TRANS_TABLES

Create Procedure "CREATE DEFINER=xxx@% PROCEDURE testutf8() begin select '?????????'; end"

character_set_client utf8

collation_connection utf8_general_ci

Database Collation latin1_swedish_ci

So despite me using SET NAMES UTF8; the server turns my code into latin1 it seems. How can I fix this?

Upvotes: 2

Views: 17423

Answers (3)

Ratha Hin
Ratha Hin

Reputation: 680

In store procedure input variable added

CHARSET utf8

So it look like this:

CREATE DEFINER=`root`@`%` PROCEDURE `post_content`(IN postName varchar(255), IN contentEn longtext, IN contentAR longtext CHARSET utf8, IN contentKU longtext CHARSET utf8)

...

Upvotes: 8

Clemens Valiente
Clemens Valiente

Reputation: 867

adding ?characterEncoding=utf8 to the server url did the trick.

Upvotes: 1

Krishna Rani Sahoo
Krishna Rani Sahoo

Reputation: 1539

Try using

delimiter //
drop procedure if exists testutf8
//
create procedure testutf8()
begin
   select CAST('ξενοδοχια' AS CHAR CHARACTER SET utf8);
end
//
delimiter ;

Upvotes: 0

Related Questions