We will receive an identifier from the user in this form:
"A-123456-14"
and want to search the database with a simple identifier in this form:
123456
I tried
select * from orders where id = '%' + searchId + '%';
here id = 123456 in the database and searchId = 'A-123456-14', which are received from the user.
but it does not work properly
(A: prefix, - delimiter and 14 - postFix)
Please help me solve this problem.
you can use:
SELECT * FROM orders WHERE WHERE 'A-123456-14' REGEXP '[:punct:]' + id + '[:punct:]';
above you can replace "A-123456-14" with user input searchId
I tried to work fine
SELECT * FROM orders WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX(searchId, '-', 2), '-',- 1)
EDIT:
, ( , ).
SELECT * FROM orders WHERE id = SUBSTRING_INDEX( SUBSTRING_INDEX(searchId, delimiter, 2), delimiter, - 1)
:
SELECT * FROM orders WHERE searchId LIKE CONCAT('%-', Id, '-%')
, , (, Java PHP , ), SQL. select * from orders where id = ? "%"+id+"%" .
select * from orders where id = ?
"%"+id+"%"
?