sql - MySQL Function Oddness When Using IN Operator -
i have below query runs ok , returns string 2,3
. fn_get_plan_upgrade_options
returning varchar
.
select fn_get_plan_upgrade_options(1);
now when add function call clause using in operator returns result act_id contains 2
, no results act_id contains 3
, there data both both should returned, suggestions or ideas, no errors thrown!?
select act_id , act_name account_types act_id in (fn_get_plan_upgrade_options(1));
the query want run this:
select ... act_id in (2,3)
but query running this:
select ... act_id in ('2,3')
because function returns string (not list of values), , since comparing string number (act_id), mysql automatically cast string number, end running this:
select ... act_id in (2)
you can use find_in_set solve problem:
select ... find_in_set(act_id, fn_get_plan_upgrade_options(1))>0