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

一世执手 提交于 2019-11-27 10:17:17

问题


I have a varchar column that contains the string lol\ncats, however, in SQL Management Studio it shows up as lol cats.

How can I check if the \n is there or not?


回答1:


SELECT *
FROM your_table
WHERE your_column LIKE '%' + CHAR(10) + '%'

Or...

SELECT *
FROM your_table
WHERE CHARINDEX(CHAR(10), your_column) > 0



回答2:


Use char(13) for '\r' and char(10) for '\n'

SELECT *
FROM your_table
WHERE your_column LIKE '%' + CHAR(10) + '%'

or

SELECT *
FROM your_table
WHERE your_column LIKE '%' + CHAR(13) + CHAR(10) + '%'



回答3:


For any fellow MySQL users who end up here:

SELECT *
FROM your_table
WHERE your_column LIKE CONCAT('%', CHAR(10), '%')



回答4:


For me, the following worked just fine in both MySQL Workbench & HeidiSQL (working with MySQL) without having to use the char() variation of \n:

SELECT * FROM table_name WHERE field_name LIKE '%\n%'



回答5:


SELECT * 
FROM Table 
WHERE PATINDEX('%' + CHAR(13) + CHAR(10) + '%', Column) > 0



回答6:


In Oracle, try the below command

SELECT * FROM table_name WHERE field_name LIKE ('%'||chr(10)||'%');


来源:https://stackoverflow.com/questions/3872270/how-can-i-check-if-an-sql-result-contains-a-newline-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!