Domanda

I have a mysql query in java like

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

Here the param ORG will have single value like xyz and CATEGORY String may have multiple values like Cat1,Cat2 etc.., So dynamically i would like to frame query using REGEX to replace the comma separated string values like

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

Thanks.

È stato utile?

Soluzione

You can use FIND_IN_SET() function instead of RegEx

Try this:

SELECT * FROM PROJECT_EMP WHERE org = :ORG AND FIND_IN_SET(category,:CATEGORY);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top