1

有没有人可以告诉我如何在 a 内获取行stored procedure

例如,假设我这样做

BEGIN 
   SELECT id, name, lastname, 
   FROM eyploees;

   --How can i process all the results within this procedure?

END<br/>
4

1 回答 1

3

您需要使用游标:

DECLARE id_var INT;
DECLARE name_var VARCHAR(255);
DECLARE lastname_var VARCHAR(255);

DECLARE my_cursor CURSOR FOR SELECT id, name, lastname FROM employees;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN my_cursor;

read_loop: LOOP

    FETCH my_cursor INTO id_var, name_var, lastname_var;
    IF done THEN
      LEAVE read_loop;
    END IF;

    --Do some row work here using _var variables from above

END LOOP;

CLOSE my_cursor;
于 2012-10-19T03:04:06.527 回答