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