主要问题我感觉可能是in的用法,还有`Schedule`表的Section字段是一个Enum格式的,取值范围是{1,2,3,4,5}其中的一个,所以用了in 来判断,在这里是想取出来`Schedule`表满足Section字段等于1或者3或者5的行,实际中,我想取出1,2,3,4,5任意1到5个值组合,即想取出Section等于1或者3,2或者5,3或者4,1或者3或者4等等任意组合的行,我用=不行,所以想用in,我现在已经确定问题出在改成存储过程以后往section变量传
值的时候,到执行时代码实际上是`Schedule`.Section in ( '1,3,5' ),和没有改成存储过程之前的区别就是值传进来的时候多了单引号,`Schedule`.Section in ( 1,3,5 )所以导致这个约束条件失效,我试着用substring函数把两侧的单引号去掉,但是不行,所以请大家帮帮忙,小弟新手,先谢谢啦。
`Schedule`.Section 代码片段1:
select CampusRegion,RoomBuilding,RoomSequence,RoomId,Capacity from ClassRoom where RoomSequence not in 
( select distinct RoomSequence from `Schedule` where find_in_set ( '4', `Schedule`.ClassTime ) > 0 
and `Schedule`.Section in ( 1,3,5 ) and `Schedule`.`Week` = '1' ) and ClassRoom.CampusRegion = '北辰' and ClassRoom.RoomBuilding = '12';把上述代码改为存储过程:
delimiter $$
drop PROCEDURE if EXISTS sp_kongxianjiaoshi $$
CREATE PROCEDURE sp_kongxianjiaoshi( region VARCHAR(20), roomBuilding VARCHAR(20), classTime VARCHAR(20),week VARCHAR(20),section VARCHAR(20))
BEGIN
select CampusRegion,RoomBuilding,RoomSequence,RoomId,Capacity,MultiFlag from ClassRoom where RoomSequence not in
( select distinct RoomSequence from `Schedule` where find_in_set ( classTime, `Schedule`.ClassTime ) > 0 
 and `Schedule`.Section in (section) and `Schedule`.`Week` = week ) and ClassRoom.CampusRegion = region and ClassRoom.RoomBuilding = roomBuilding;
select section as hah;
END $$
delimiter ;调用存储过程:call sp_kongxianjiaoshi('北辰','12','4','1','1,3,5');
运行结果:发现and `Schedule`.Section in (section)这一句完全没有作用了,没有过滤掉我想要过滤的数据。
其他字段都没有问题,问题出在section