我想传入一个int值并得到一个短密码列表,短密码小于这个int值。我在修改MySQL游标时遇到了问题,例如:http://dev.mysql.com/doc/refman/5.0/en/cursors.html。我想用短密码打印出行,但是任何时候只要结果有多行PhpMyAdmin就无限期地显示“处理请求”。我做错什么了?它毁了我周六的工作效率!

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ShortPasswd`(IN `passwordLength` TINYINT)
BEGIN
  DECLARE done INT DEFAULT FALSE;
  DECLARE a INT;
  DECLARE b VARCHAR(255);
  DECLARE cur1 CURSOR FOR SELECT UID, Password
      FROM authentication WHERE CHARACTER_length(Password) < passwordLength;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

  OPEN cur1;

  read_loop: LOOP
    FETCH cur1 INTO a, b;
    IF done THEN
      LEAVE read_loop;
    END IF;
    SELECT b;
  END LOOP;

  CLOSE cur1;
END
$$
DELIMITER ;

最佳答案

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ShortPasswd`(IN `passwordLength` TINYINT)
BEGIN

   SELECT UID, Password
      FROM authentication WHERE CHARACTER_length(Password) > passwordLength;

END
$$
DELIMITER ;

您将直接获得行UID和密码。当您从查询中得到
call ShortPasswd;

关于mysql - 在存储过程中打印出多行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16120960/

10-12 20:39