如何检查 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 07:49:34  来源:igfitidea点击:

How can I check if an SQL result contains a newline character?

sqlsql-serverssms

提问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 \nis 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