简体   繁体   中英

How SQL/sqlite wildcars work? LIKE operator

How wildcards in sqlite work. Or how LIKE operator matches. For examle lets say:

1: LIKE('s%s%', 's12s12')
2: LIKE('asdaska', '%sk%')

In 1st example what % matches after 1st s , and how it decides to continue matching % or s after % .
In 2nd example if s matches first then FALSE returned.
Both examples return TRUE . From my Programming knowledge I came up with that LIKE function is some like a recursive function that when 2 possibilities appear function calls itself with 2 different params and uses OR between them, then obviously if one call returns true, upper function directly returns true. If it is so, then LIKE operator is quiet slow to use on large DBs. PS There is one more '_' wildcard which matches exactly one character
I couldnt find any detailed documentation of LIKE operator.

% matches zero or more characters, _ matches exactly one.

Your first pattern 's%s%' would match, 'ss' , 's1s' , 's1111s' , 'ss1111' , etc. etc.

However if you wrote 's_s_' it would match 's1s1' , but none of the above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM