728x90

구조

delimiter //
create procedure test10()
begin
	declare v_stu_no char(9);
   	declare v_sub_no char(3);
    declare v_enr_grade int;
    declare done int default 0;

declare endOfRow boolean default false; -- 행의 끝 여부

declare c1 cursor for select stu_no, sub_no, enr_grade from enrol where sub_no=104;

declare continue handler for not found set done=1;
-- 더 이상 읽을 행이 없으면 1

open c1;
li:loop
	fetch from c1 into v_stu_no, v_sub_no, v_enr_grade;
    if done then leave li;
    end if;
    select v_stu_no, v_sub_no, v_enr_grade;
    end loop;
    close c1;
end //
delimiter ;

call test10;
728x90

'DBMS > MySQL' 카테고리의 다른 글

[MySQL] IF-Then/Case-when-then/Set-While-do  (0) 2024.03.21
[MySQL] 트리거(Trigger)  (0) 2024.03.20
[MySQL] 쿼리 종합예시  (0) 2024.03.19
[MySQL] 스토어드 프로시저  (0) 2024.03.18
[MySQL] 뷰(View)  (0) 2024.03.18

+ Recent posts