在获取游标时 crnt_user_skills 从表中获取所有数据,而不是获取特定用户 ID 的数据。我什至尝试手动提供特定的用户标识,但从表中获取所有数据而不是给定的用户标识。我的代码有什么问题?请帮忙?实际上,游标 user_data 中出现了多个游标,我只在 user_data 游标中给出了一个游标。变量声明实际上是针对所有游标的,不要对此感到恐慌。
DELIMITER $$
CREATE PROCEDURE test2(IN latd FLOAT(10,6),IN lngtd FLOAT(10,6),IN user_ind INT,IN userid INT,user_exprts INT,user_intn INT,regdate TIMESTAMP)
COMMENT 'To list users within 150 miles range'
BEGIN
DECLARE user_cnt_hndlr,ind_cnt_hndlr,exprts_cnt_hndlr,crnt_events_cnt_hndlr,mchd_uid,mchd_ind,mchd_clustered_industry_id,mchd_exprts,mchd_clustered_expertise_id,mchd_intn,weight_score,prev_ind_score,prev_exprts_score,user_event_id,user_skl_id,user_strngth,skl_cnt,user_skills_cnt_hndlr INT;
DECLARE mchd_miles VARCHARACTER(50);
DECLARE user_bosi_result CHAR(2);
DECLARE mchd_regdate TIMESTAMP;
DECLARE user_data CURSOR FOR
SELECT DISTINCT ((ACOS(SIN(latd * PI() / 180) * SIN(users.lat * PI() / 180) + COS(latd * PI() / 180) * COS(users.lat * PI() / 180) * COS((lngtd - users.lang) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance`,`users`.`id` AS `userid`, `users`.`industry`, `users`.`user_expertise`, `users`.`user_intention`, `users`.`reg_date`
FROM `users`
WHERE user_status = 'A'
AND id <> userid
HAVING distance <=250;
DECLARE crnt_user_skills CURSOR FOR
SELECT skillid,strength FROM user_skills WHERE userid = userid ORDER BY skillid ASC;
SET weight_score = 0;
user_data_section : BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET user_cnt_hndlr = 1;
OPEN user_data;
user_cursor_loop: LOOP
FETCH user_data INTO mchd_miles,mchd_uid,mchd_ind,mchd_exprts,mchd_intn,mchd_regdate;
IF user_cnt_hndlr = 1 THEN
LEAVE user_cursor_loop;
END IF;
skill_section : BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET user_skills_cnt_hndlr = 1;
SET skl_cnt = 0;
OPEN crnt_user_skills;
usr_skl_loop : LOOP
FETCH crnt_user_skills INTO user_skl_id,user_strngth;
IF user_skills_cnt_hndlr = 1 THEN
LEAVE usr_skl_loop;
END IF;
SET skl_cnt = getSkillsCount(skl_cnt,user_skl_id,user_strngth,mchd_uid);
INSERT INTO recmd_cnds_test(usr_ind1,matchd_ind1,industry_id1,clustered_industry_id1,bosi) VALUES(userid,user_skl_id,user_strngth,mchd_uid,'SI');
END LOOP usr_skl_loop;
CLOSE crnt_user_skills;
SET user_skills_cnt_hndlr = 0;
SET weight_score = calculateSkillsWeightScore(weight_score,skl_cnt);
END skill_section;
INSERT INTO `recmd_cnds` (`user_id` ,`recmd_id` ,`wgt_score`)VALUES (userid, mchd_uid, weight_score);
END LOOP user_cursor_loop;
CLOSE user_data;
SET user_cnt_hndlr = 0;
END user_data_section;
END$$