Mysql存储过程不返回任何值

时间:2023-02-04 16:36:45

This is the first time I am working on Mysql stored procedure I know it is a lame question please spare me for this,

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

is it not possible to print any value after the END LOOP statement in MySQL procedure. If it is, how we can achieve this. what I did for this:

是不可能在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 个解决方案

#1


0  

You should use id2 instead of id in your last query.

您应该在上次查询中使用id2而不是id。

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

#1


0  

You should use id2 instead of id in your last query.

您应该在上次查询中使用id2而不是id。

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