Home > other >  How to call certain string in MYSQL Stored Procedure
How to call certain string in MYSQL Stored Procedure

Time:11-01

Here's my input data: https://i.stack.imgur.com/K3WrM.png

If user input data like:

> CALL Hobbies_Input('football')
> 
> CALL Hobbies_Input('Badminton')
> 
> CALL Hobbies_Input('Cricket')

They should get their respective outputs.

I tried to do this, Here's my stored procedure:

DELIMITER &&
CREATE PROCEDURE Hobbies_Input (IN var1 VARCHAR(50))
BEGIN  
    SELECT * FROM sample_data WHERE FIND_IN_SET(Hobbies, var1);
END &&
DELIMITER;

It's working for my first case[CALL Hobbies_Input('football')] But its showing zero rows for my second and third case, how can i rectify this?

CodePudding user response:

does this work?

DELIMITER &&
CREATE PROCEDURE Hobbies_Input (IN var1 VARCHAR(50))
BEGIN  
    SELECT * FROM sample_data WHERE FIND_IN_SET(REPLACE(Hobbies, ';', ','), var1);
END &&
DELIMITER;
  • Related