REGEX mysql用于逗号分隔值

时间:2013-12-26 11:02:30

标签: mysql sql regex select find-in-set

我在java中有一个mysql查询,如

public static BusObjectIterator<con.PROJECT_EMP> GetEmpObjectsforOrgandMultipleCategory(String ORG, String CATEGORY)
    {
String query=select * from PROJECT_EMP where org = :ORG and category=:CATEGORY;
.....
return ...
}

这里param ORG将具有单个值,如xyz和CATEGORY String可能有多个值,如Cat1,Cat2等.., 所以我想动态地使用REGEX来构建查询,以替换逗号分隔的字符串值,如

select * from PROJECT_EMP where org = 'xyz' and category in ('Cat1','Cat2');

感谢。

1 个答案:

答案 0 :(得分:3)

您可以使用FIND_IN_SET()功能代替RegEx

试试这个:

SELECT * FROM PROJECT_EMP WHERE org = :ORG AND FIND_IN_SET(category,:CATEGORY);