是否有人可以告诉我如何在stored procedure
内获取行?
比方说我做
BEGIN
SELECT id, name, lastname,
FROM eyploees;
--How can i process all the results within this procedure?
END<br/>
答案 0 :(得分: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;