开发者

How do/Can I use LIKE in a MySQL view?

开发者 https://www.devze.com 2023-04-12 23:58 出处:网络
If I create a view like so: CREATE VIEW test_view AS SELECT * FROM mytable WHERE somevalue LIKE \'test%\';

If I create a view like so:

CREATE VIEW test_view AS SELECT * FROM mytable WHERE somevalue LIKE 'test%';

...it looks like this when I come back to edit it (so obviously it doesn't work):

CREATE VIEW test_view AS SELECT * FROM mytable WHERE somevalue LIKE '\0\0\0t\0\0\0e\0\0\0s\0\0\0t\0\0\0%';

What am I doing wrong? LIKE must be allowed in a view, so maybe the string should be escaped in s开发者_StackOverflow社区ome way?


What you’re seeing is obviously UTF-32, so your environment is apparently set up to use that encoding and not ASCII. It is not necessarily a bad thing, but you need to set it up to display the character correctly (instead of the byte values); and also to make sure that the back-end really is using UTF-32 as well.

Other than that, it’s really hard to help if you don’t tell us how you edit and run your commands (where do you “come back” after you’ve typed the SQL command?).

0

精彩评论

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

关注公众号