SQL select where column begins with \

醉酒当歌 提交于 2019-12-18 09:23:07

问题


I'm trying to find all the data in ColumnX where the Data begins with a \.
Is like '\%' what I'm looking for? But the \ has to be at the beginning.


回答1:


Your syntax would work in standard SQL, because \ is not a meta character in strings. But it very much depends on which DBMS and version you are actually using - and what your current settings are.

In PostgreSQL POSIX-style escapes in strings used to be interpreted, so you would have to double \ to \\ to get an ordinary backslash.

The SQL standard says otherwise. So the PostgreSQL people have been preparing to switch over to standard behavior for years, introduced the special escape-string-syntax E'' and a config setting escape_string_warning to make people aware of ambiguous syntax.

With version 9.1 they finally switched to "standard-conforming" strings. Now, if the global user configuration uses standard_conforming_strings = on, you can simply write:

... col like '\%' 

Else you have to write:

... col like E'\\%'

Also, be aware that \ has special meaning in many client programs and programming languages. If strings get interpreted before they even reach the database engine, you may have to double the \ another time. See this related question, for instance.




回答2:


Indeed '\%' is what you need. The following statement brings all the data where columnX starts with '\'.

select * from table_name where columnX like '\%' 



回答3:


this is what you need




回答4:


try this...

select * from myTable where ColumnX like '\%'

Good Luck!!!



来源:https://stackoverflow.com/questions/9141521/sql-select-where-column-begins-with

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