Reputation: 923
I am new to REGEX. So,I tried:
select * from ot.contacts where REGEXP_like(last_name,'^[A-C]');
Also,I tried:
select * from ot.contacts where REGEXP_like(last_name,'[A-C]');
both of them are giving me output where last_name starts with A,b,c and the no of records fetched is same.Can you tell me when I can see difference using this caret symbol?
Upvotes: 0
Views: 304
Reputation: 222482
In this context, ^
represents the beginning of the string.
'^[A-C]'
checks for A, B or C at the beginning of the string.
'[A-C]'
checks for A, B or C at the anywhere in the string.
Depending on your dataset, both expressions might, or might not produce the same output. Here is on example where the resultset would be different:
last_name | ^[A-C] | [A-C]
----------------- | ------- | -----
Arthur | match | match
Bill | match | match
Jean-Christophe | no match | match
Upvotes: 5