1. Cusor For Loop
    1. Open cursor
      1. declare
        1. cursor c8 is
          1. select initcap(author_last_name) l_name, initcap(author_first_name) f_name from author;
      2. begin
        1. for r_c8 in c8 loop
          1. dbms_output.put_line(r_c8.f_name||' '||r_c8.l_name);
        2. end loop;
      3. end; /
    2. 루프
      1. declare
        1. cursor c9 is
          1. select sum(quantity) qty from sales group by store_key;
        2. sumer number := 0;
        3. counter number := 0;
      2. begin
        1. for r_c9 in c9 loop
          1. sumer := sumer + r_c9.qty;
          2. counter := c9%rowcount;
        2. end loop;
        3. dbms_output.put_line('Average is '||sumer/counter);
      3. exception
        1. when others then
          1. if c9%isopen then close c9;
        2. end if;
      4. end; /
    3. row별 Fetch하기
      1. declare
        1. cursor c10(v_avg in number) is
          1. select store_name, sum(quantity) qty from store join sales using (store_key) group by store_name having sum(quantity) > v_avg;
      2. begin
        1. for r_c10 in c10 (11055) loop
          1. dbms_output.put_line(initcap(r_c10.store_name)||' '||r_c10.qty);
        2. end loop;
      3. end; /
    4. 신규row확인과종료
      1. declare
        1. cursor c10(v_avg number:= 11055) is
          1. select store_name, sum(quantity) qty from store join sales using (store_key) group by store_name having sum(quantity) > v_avg;
      2. begin
        1. for r_c10 in c10 loop
          1. dbms_output.put_line(initcap(r_c10.store_name)||' '||r_c10.qty);
        2. end loop;
      3. end;
    5. 데이타 진행하기
      1. begin
        1. for r_c11 in (select author_last_name l_name,author_first_name f_name from author) loop
          1. dbms_output.put_line(initcap(r_c11.l_name||', '||r_c11.f_name));
        2. end loop;
      2. end;
    6. Loop 종료하기
      1. begin
        1. for r_c11 in
          1. (select author_last_name l_name,author_first_name f_name from author) loop
          2. dbms_output.put_line(initcap(r_c11.l_name|| ', '||r_c11.f_name));
        2. end loop;
      2. end;
    7. Cursor 종료하기
      1. begin
        1. for r_c11 in (select author_last_name l_name,
          1. author_first_name f_name
          2. from author) loop
          3. begin
          4. dbms_output.put_line(initcap(r_c11.l_name||', '||r_c11.f_name));
          5. -- lots of other stuff to do.
          6. exception
          7. when others then
          8. -- handle all exceptions
          9. end;
        2. end loop;
      2. end;
    8. 커셔예제
  2. Procedure
    1. DECLARE
      1. s_empno varchar2(10)
      2. s_string varchar2(20)
    2. BEGIN
      1. FOR cur_uptest IN (
        1. SELECT A.EMPNO,B.DEPT_NAME FROM EMP E,DEPT D
      2. ) LOOP
        1. s_empno := cur_uptest.empno;
        2. s_string := cur_uptest.dept;
        3. update personnel set address = s_string where empno = s_empno;
      3. END LOOP;
    3. END;