SQL语言中Where IN的有关问题 select * from table where group_name in ('"' + replace(tmp,',','","') + '"')不同的数据库replace函数不同 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这就和具体的数据库有关了因为'是特殊字符select * from table where group_name in (''''+replace(tmp,',',''',''') + '''') 这种写法和你上面的写法倒是不出错,但查询不到记录。我用的是mysql。select * from t_group_list where group_name in( replace("A_VIP,B_VIP", "," ,"\",\"")); 不要这样用把replace换成应用程序的函数,把sql拼起来aaa=replace("A_VIP,B_VIP", "," ,"\",\"");"select * from t_group_list where group_name in('"+aaa+"');"再执行 已经解决了String destGroupName = req.getParameter("selectGroupName");System.out.println(destGroupName); //destGroupName如"AB,CD"的格式String[] splitStr = destGroupName.split(",");StringBuffer whereIN = new StringBuffer(); for(int i=0; i<splitStr.length; i++){ whereIN.append("\"" + splitStr[i] + "\"").append(","); }//去掉最后一个,号whereIN = whereIN.deleteCharAt(whereIN.lastIndexOf(","));多谢 192168001001(汉族程序员) ! 一个小型数据库的模块划分问题及其所涉及的数据结构 mysql 数据文件 安装mysql时出现10061错误,急!!!!! mysql 5.6的绿化让我崩溃了。系统错误 1067 txt 数据导入到mysql的疑问 带有自动增长列的一个表,取出一条记录后,会带有这个字段的值吗? 终于升星了,散分! 查询最大值 可不可以pj网络上某个mysql root密码? redhat 7.1 的mysql为何装不上 mysql中是否支持top n *? (sql)请教一条语句,统计表中记录的有多少条,重复的不算.比喻下表,求表中"张三"的记录有多少条?
因为'是特殊字符
select * from table where group_name in (''''+replace(tmp,',',''',''') + '''')
这种写法和你上面的写法倒是不出错,但查询不到记录。我用的是mysql。select * from t_group_list where group_name in( replace("A_VIP,B_VIP", "," ,"\",\""));
把replace换成应用程序的函数,把sql拼起来
aaa=replace("A_VIP,B_VIP", "," ,"\",\"");
"select * from t_group_list where group_name in('"+aaa+"');"
再执行
System.out.println(destGroupName); //destGroupName如"AB,CD"的格式String[] splitStr = destGroupName.split(",");
StringBuffer whereIN = new StringBuffer();
for(int i=0; i<splitStr.length; i++)
{
whereIN.append("\"" + splitStr[i] + "\"").append(",");
}
//去掉最后一个,号
whereIN = whereIN.deleteCharAt(whereIN.lastIndexOf(","));多谢 192168001001(汉族程序员) !