开发者

How do I use ESCAPE in SQLite?

开发者 https://www.devze.com 2023-01-15 11:58 出处:网络
Trying this answer and not having any luck: I am using the SQLite Database browser (built with 3.3.5 of the SQLite engine) to execute this query:

Trying this answer and not having any luck:

I am using the SQLite Database browser (built with 3.3.5 of the SQLite engine) to execute this query:

SELECT columnX FROM MyTable

WHERE columnX LIKE  '%\%16'  ESCAPE '\'  

I开发者_运维知识库n column XI have a row with the data: sampledata%167

I execute the statement and get no data returned but no error either?

http://www.sqlite.org/lang_expr.html

(SQLite with C API)


I think the problem is that you are missing a % from the end of the pattern.

'%\%16%'

Also backslashes often cause confusion in various programming languages and tools, especially if there is multiple levels of parsing involved before the query gets to the database. To simplify things you could try a different escape character instead:

WHERE columnX LIKE '%!%16%' ESCAPE '!'


Your sample data ends in %167, but your query only matches things which end in %16. You may need to change your query to have a trailing % or end with 167 as your data does, depending on your needs.

When I try this in SQLite, it works just fine:

sqlite> create table foo (bar text);
sqlite> insert into foo (bar) values ('sampledata%167');
sqlite> select * from foo where bar like '%\%16' escape '\';
sqlite> select * from foo where bar like '%\%167' escape '\';
sampledata%167

You may want to try experimenting with this in the SQLite shell, on a simple example table like I show, to see if your problem still exists there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号