The requirements are a bit different in different parts or your post but if the following is correct
Tech Box To Unbox wrote:
Let us consider there are 50 records in my table. If i pass "p_Bot_Ids" = "1,2,3" I needs to get only 1,2,3 Ids records(total 3 rows) only. If I pass "p_Bot_Ids" = NULL then I should get all my 50 records.
You could try something like
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_get_logs_Test`(IN `p_Bot_Ids` VARCHAR(500))
NO SQL
SET @sql := 'select id, bot_id, log_level,log_type,time_stamp,finger_print,windows_identity,machine_name,process_name,process_version
,job_Id,robot_name,machine_Id,file_name,message,created_date from log
where id < 200';
IF p_Bot_Ids IS NOT NULL THEN
SET @sql := CONCAT(@sql, ' AND bot_id IN (', p_Bot_Ids, ')');
END IF ;
PREPARE mystatement FROM @sql;
EXECUTE mystatement;
DEALLOCATE PREPARE mystatement$$
DELIMITER ;
For more information, have a look at
MySQL :: MySQL 8.0 Reference Manual :: 13.5.1 PREPARE Statement[
^]