如何检查 SQL 结果是否包含换行符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3872270/
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
How can I check if an SQL result contains a newline character?
提问by NibblyPig
I have a varchar column that contains the string lol\ncats
, however, in SQL Management Studio it shows up as lol cats
.
我有一个包含 string 的 varchar 列lol\ncats
,但是,在 SQL Management Studio 中它显示为lol cats
.
How can I check if the \n
is there or not?
我如何检查是否\n
存在?
回答by LukeH
SELECT *
FROM your_table
WHERE your_column LIKE '%' + CHAR(10) + '%'
Or...
或者...
SELECT *
FROM your_table
WHERE CHARINDEX(CHAR(10), your_column) > 0
回答by Sachin Shanbhag
Use char(13)
for '\r'
and char(10)
for '\n'
使用char(13)
了'\r'
和char(10)
用于'\n'
SELECT *
FROM your_table
WHERE your_column LIKE '%' + CHAR(10) + '%'
or
或者
SELECT *
FROM your_table
WHERE your_column LIKE '%' + CHAR(13) + CHAR(10) + '%'
回答by Taran
For any fellow MySQL users who end up here:
对于最终到达这里的任何其他 MySQL 用户:
SELECT *
FROM your_table
WHERE your_column LIKE CONCAT('%', CHAR(10), '%')
回答by dksadiq
For me, the following worked just fine in both MySQL Workbench & HeidiSQL (working with MySQL) without having to use the char()
variation of \n
:
对我来说,以下在 MySQL Workbench 和 HeidiSQL(使用 MySQL)中都可以正常工作,而无需使用 的char()
变体\n
:
SELECT * FROM table_name WHERE field_name LIKE '%\n%'
回答by Annie Jeba
In Oracle, try the below command
在 Oracle 中,尝试以下命令
SELECT * FROM table_name WHERE field_name LIKE ('%'||chr(10)||'%');
回答by Nungster
SELECT *
FROM Table
WHERE PATINDEX('%' + CHAR(13) + CHAR(10) + '%', Column) > 0