开发者

Ö (O with double dots) in Mysql record?

开发者 https://www.devze.com 2022-12-11 05:56 出处:网络
I have a row in a MySQL table with \"ö\". The whole word is \"företag\". How do I select that word in a sql query?

I have a row in a MySQL table with "ö". The whole word is "företag".

How do I select that word in a sql query?

I've tried with fö开发者_Go百科retag but it didn't work. The table is using utf8.


You could use:

SELECT * FROM table WHERE field LIKE 'f_retag';

('_' is the single character wildcard for LIKE statements)

If you are using a terminal, make sure the terminal is using UTF-8. Try:

 echo $LANG

Also try forcing the character set when starting the mysql command:

 mysql --default-character-set=utf-8

Otherwise, please give more details about what language and environment you are using to access the DB.


You can also try running following query before running your select:

SET CHARACTER SET utf8;

Just tested it on my local MySQL (the table was created with UTF8 charset):

mysql> select * from xxx where s='företag';
+----------+
| s        |
+----------+
| företag |
+----------+
1 row in set (0.00 sec)


Try this

declare @tbl table(name varchar(50))
insert into @tbl select 'företag' union all select 'foretag'

SELECT * FROM @tbl WHERE name = 'företag';

SELECT * FROM @tbl WHERE name like '%ö%';


There is more than one way to write an accented character in Unicode. For example, "Ä" can also be written as "A\u0308". The relevant Unicode document is "Unicode Normalization Forms", but it is not easy reading.

0

精彩评论

暂无评论...
验证码 换一张
取 消