SQL拼接结果集,并且带转义字符单引号,适合组装in的条件

"select wm_concat(''''||t.bank_names||'''') as bankNames from tb_adjust_bank_bak t where t.bank_code = '"+tradeAccountname+"'"

下面为grails框架使用该策略的一个简单用例(查询模糊银行,例如同样为ICBC的可以模糊为工行、工商银行、中国工商银行)

/**
* 查询银行并拼接字符串
* @param tradeAccountname
* @return
*/
def findTradeAccountnamesForStr (String tradeAccountname) {
String bankNames = '';
def sql = new Sql(DatasourcesUtils.getDataSource("dsf"))
def strSql= "select wm_concat(''''||t.bank_names||'''') as bankNames from tb_adjust_bank_bak t where t.bank_code = '"+tradeAccountname+"'";

sql.eachRow(strSql) {

bankNames = it.bankNames;
}
println bankNames;
return bankNames;
}

你可能感兴趣的:(转义字符)