<샘플코드에서 사용한 데이터는 HR 스키마이고, 오라클 설치시 생성할 수 있는 기본 스키마 입니다>
#basic loop
#write a basic loop to print 'welcome' 3 times
declare
v_counter number:=0;
begin
loop
v_counter:=v_counter+1;
dbms_output.put_line('welcome ' ||v_counter);
exit when v_counter>=3;
end loop;
end;
--------------------------------------
#another method
declare
v_counter number:=0;
begin
loop
v_counter:=v_counter+1;
dbms_output.put_line('welcome ' ||v_counter);
if v_counter>=3 then
exit;
end if;
end loop;
end;
# print the employees first name for employee 100,101,102
# using basic loop
declare
v_empno number:=100;
v_first_name employees.first_name%type ;
begin
loop
exit when v_empno>102;
select first_name into v_first_name
from employees
where employee_id = v_empno;
dbms_output.put_line(v_empno ||' '|| v_first_name);
v_empno:=v_empno+1;
end loop;
end;
'Database > PLSQL' 카테고리의 다른 글
010 - [Oracle PL/SQL] For Loop (0) | 2024.02.09 |
---|---|
009 - [Oracle PL/SQL] While Loop (0) | 2024.02.08 |
007 - [Oracle PL/SQL] CASE expression & CASE Statement (0) | 2024.02.08 |
006 - [Oracle PL/SQL] IF Statement (1) | 2024.02.08 |
005 - [Oracle PL/SQL] Implicit Cursor(암시적 커서) (0) | 2024.02.08 |