I have a procedure A which takes an array of strings. By calling another procedure B, i break this array in this format:
'1','2','3','4'
In case there is only one value, it just displays as '1'
I want to return *
in case the array passed to the procedure A.
Therefore, my query will be like this: select * from users where userId(*);
What i want is that in case the parameter is null, it should still perform the IN using.
** EDIT ** Nothing much of query
CREATE DEFINER=`root`@`localhost` PROCEDURE `listAll`(IN id varchar(200))
BEGIN
set @t = lib_explode(',',id);
select * from city where ID in(@t);
END
Procedure B
CREATE DEFINER=`root`@`localhost` FUNCTION `lib_explode`(sSepar VARCHAR(255), saVal TEXT) RETURNS varchar(200) CHARSET utf8
body:
BEGIN
IF sSepar IS NULL OR saVal IS NULL THEN LEAVE body; END IF;
SET @saTail = saVal;
SET @iSeparLen = LENGTH( sSepar );
set @mystring = '';
set @current_pos = 1;
create_layers:
WHILE @saTail != '' DO
# Get the next value
SET @sHead = SUBSTRING_INDEX(@saTail, sSepar, 1);
SET @saTail = SUBSTRING( @saTail, LENGTH(@sHead) + 1 + @iSeparLen );
-- INSERT INTO lib_Explode SET val = @sHead;
if(@current_pos > 1) then
set @mystring = concat(@mystring,',',concat("'",@shead,"'"));
else
set @mystring = concat(@mystring,concat("'",@shead,"'"));
end if;
set @current_pos = @current_pos + 1;
END WHILE;
return @mystring;
END