Mysql存储过程不返回任何值

时间:2016-05-23 13:01:48

标签: mysql loops stored-procedures cursor

这是我第一次使用Mysql存储过程时,我知道这是一个蹩脚的问题请为此饶恕我,

是不可能在MySQL过程中的END LOOP语句之后打印任何值。如果是,我们如何才能实现这一目标。 我为此做了什么:

BEGIN
    DECLARE U_movingCity varchar(50); 
    DECLARE U_state varchar(50); 
    DECLARE U_education varchar(50);

    DECLARE id2 int(10);
    DECLARE RankPoint int(10) DEFAULT 0;

    DECLARE movingCity2 varchar(50); 
    DECLARE state2 varchar(50); 
    DECLARE education2 varchar(50);

    DECLARE cur1 CURSOR FOR SELECT id, state , education FROM user WHERE id != userid AND Enabled='y' AND Active='y';

    SELECT  state , education  into U_state , U_education  FROM user WHERE id = userid ;

 OPEN cur1;
 read_loop: LOOP
    SET RankPoint := 0;
    FETCH cur1 INTO id2, state2 , education2 ;

    IF ((state2 = U_state)) THEN 
        SET RankPoint := RankPoint + 14;
    END IF;
    IF ((education2 = U_education)) THEN    
        SET RankPoint := RankPoint + 16;
    END IF;
    //this displays 
    select RankPoint;

  END LOOP;

  //this doesn't.
  select id, RankPoint from user;
  CLOSE cur1;
END

1 个答案:

答案 0 :(得分:0)

您应该在上次查询中使用id2代替id

select `id2`, `RankPoint` from `user`;