| |

VerySource

 Forgot password?
 Register
Search
View: 1025|Reply: 7

Problems with like special characters in sql statements

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-13 21:00:02
| Show all posts |Read mode
name
_twenty three_
_3_


select name from table where name like '% _3_%'

This statement will select all the above 2 records. Don't believe you guys try it, didn't notice it before.
The first one is not what I want, is it _ special treatment?
Reply

Use magic Report

1

Threads

23

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-4-11 22:30:01
| Show all posts
I have n’t really tried it yet. Then put it in []
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-4-12 00:45:02
| Show all posts
select name from table where name like '%\_3\_%' escape '\'
Reply

Use magic Report

0

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-4-12 03:30:02
| Show all posts
where name like '% [_] 3 [_]%'
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-4-12 20:45:01
| Show all posts
declare @ta table (name varchar (10))
insert @ta
select '_23_'
union select '_3_'

--select name from @ta where name like '% _3_%' this way will not work without escaping
With ESCAPE:

select name from @ta where name like '%! _ 3! _%' ESCAPE '!'

(The number of rows affected is 2)

name
----------
_3_

(The number of rows affected is 1 row)
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-4-12 21:15:02
| Show all posts
Use ESCAPE_ to escape common symbols
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-4-14 16:00:01
| Show all posts
select * from
(
select col = '_ 23_'
union all select '_3_'
) a where col like '% a_3_%'
escape 'a'

--result
col
----
_3_

(1 row (s) affected)
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

Post time: 2020-4-16 16:45:01
| Show all posts
ESCAPE is a good thing
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list