I want to match a String using Like operator. The challenge is having '%' as a character in my string.
i.e. Row1 : Column = CT%CNV!XYZABCD...
Row2 : Column = CTXXXCNV!XYZABCDE...
If I use "SELECT * FROM table WHERE Column like 'CT%CNV!%'. It doesn't consider '%' as a character and the statement returns both rows.
I need to return the first row only.
In order to find the count of matching characters in two Java strings the approach is to first create character arrays of both the strings which make comparison simple. After this put each unique character into a Hash map.
?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).
The simplest and very common pattern matching character operators is the . This simply allows for any single character to match where a . is placed in a regular expression. For example /b.t/ can match to bat, bit, but or anything like bbt, bct ....
You shoud use escape keyword:
select *
from MyTable
where Column like 'CT\%CNV!XYZABCD%' escape '\'
here '\%'
is treated as a plain symbol, while '%'
is wild card one
You can use brackets to escape the percent sign :
SELECT * FROM table WHERE Column like 'CT[%]CNV!%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With