日期:2014-05-18  浏览次数:20703 次

MySql 存储过程里面 重构字符串
我现在在前台传入数据为
call SelectScore('430000,110000,120000,23000')



CREATE DEFINER = `root`@`%` PROCEDURE `SelectScore`(
  s_SchoolProvinceID varchar(200)
)
begin
select 
  *
from t_tdscore where s_StudentProvinceID in(s_SchoolProvinceID );
end;


s_SchoolProvinceID 这个串求解析

------解决方案--------------------
try
SQL code
select  
  *
from t_tdscore where FIND_IN_SET(s_StudentProvinceID,s_SchoolProvinceID)>0;

------解决方案--------------------
SQL code
CREATE TABLE IF NOT EXISTS `test` (  
 `id` int(8) NOT NULL auto_increment,  
  `name` varchar(255) NOT NULL,  
 `list` varchar(255) NOT NULL,  
  PRIMARY KEY  (`id`)  
);  
  
INSERT INTO `test` VALUES (1, 'name', 'daodao,xiaohu,xiaoqin');  
INSERT INTO `test` VALUES (2, 'name2', 'xiaohu,daodao,xiaoqin');  
INSERT INTO `test` VALUES (3, 'name3', 'xiaoqin,daodao,xiaohu');  


select * from `test` where FIND_IN_SET('daodao',`list`);  

/*1    name    daodao,xiaohu,xiaoqin
2    name2    xiaohu,daodao,xiaoqin
3    name3    xiaoqin,daodao,xiaohu
*/