MySQL SELECT INTO OUTFILE WITH "WHERE" 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12938430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:13:20  来源:igfitidea点击:

SELECT INTO OUTFILE WITH "WHERE" statement

mysql

提问by Dima Knivets

I'm trying to export the DB records from the table via "SELECT INTO OUTFILE". Everything works. But I need to filter the records and this is the problem. Here's the code:

我正在尝试通过“SELECT INTO OUTFILE”从表中导出数据库记录。一切正常。但我需要过滤记录,这就是问题所在。这是代码:

SELECT * INTO OUTFILE 'file.txt' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
FROM table_name WHERE name LIKE '%John%' AND LENGTH(name) <= 10 ORDER BY name

This statement doesn't work, but if I remove the "name LIKE '%John%'" condition, it works. But I need to specify this LIKE condition, how can I accomplish it?

这个语句不起作用,但如果我删除“name LIKE '%John%'”条件,它就起作用了。但是我需要指定这个 LIKE 条件,我该如何实现呢?

Thanks.

谢谢。

采纳答案by juergen d

Could be a problem with the %sign. Try replacing

可能是%标志有问题。尝试更换

WHERE name LIKE '%John%'

with

WHERE LOCATE(name, 'John') > 0