I have a table called Contacts with a field called person_id that I have connected to a java application.
If no value is specified for person_id in the application, I want to select everything from the contacts table using a stored procedure.
The operation I want to perform is this:
Select * from Contacts where (person_id like "%")
CREATE DEFINER=`root`@`localhost` PROCEDURE `selectTest2`(In p_id int(11))
if p_id = null then
set p_id = "%";
select * from Contacts where (person_id like p_id);
Try using case statement in where clause like below
WHERE CASE WHEN p_id IS NOT NULL THEN person_id = p_id ELSE TRUE END
Hope this should solve your problem