I have one address table in that postcode column is there let me explain the scenarios
For example:- 523272 records are there
- if i search with 5232 i don’t want to get results.
- if i search with 523272(Exact match) i need to get results.
- if i search with 5232725656 Now also i need to fetch results related to 523272 records (starts equals to condition).
i tried for this one wildcard entries and length it’s not working,can you help me to achieve this scenario.
SELECT * FROM WHERE postcode LIKE '%523272';
3
Answers
You should reverse the condition. Append the wildcard to the column value, and match the search string against that pattern.
DEMO
Note that this can’t be indexed, so it will be slow on a large table.
You can try this I have tested all possible values and @post is a variable in which you can set your value
Ex :
Probably you should use Regex_Like operator along with Substring and RPAD. Following might work:
SELECT * FROM WHERE REGEX_LIKE (postcode, concat(RPAD(SUBSTRING('SEARCHSTRING', 1, 6), 6, '?'), '.+'));