Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
РСБДтЗ / Курс лекций РСБДиЗ.doc
Скачиваний:
135
Добавлен:
05.03.2016
Размер:
1.63 Mб
Скачать

Именованные блоки

<<my_block>>

declare

a number := 10;

b number := 20;

begin

dbms_output.put_line(a);

dbms_output.put_line(b);

declare

a number;

c number;

begin

a := 30;

c := 40;

dbms_output.put_line('---->'||my_block.a);

dbms_output.put_line('---->'||a);

dbms_output.put_line('---->'||b);

dbms_output.put_line('---->'||c);

end;

dbms_output.put_line(a);

dbms_output.put_line(b);

end;

<<my_block1>>

declare

a number := 10;

begin

dbms_output.put_line('my_block1 '||a);

<<my_block2>>

declare

a number := 20;

begin

dbms_output.put_line('my_block2 '||my_block1.a);

dbms_output.put_line('my_block2 '||a);

<<my_block3>>

declare

a number := 30;

begin

dbms_output.put_line('my_block3 '||my_block1.a);

dbms_output.put_line('my_block3 '||my_block2.a);

dbms_output.put_line('my_block3 '||a);

end;

end;

dbms_output.put_line('my_block1 '||a);

end;

Управляющие конструкции

declare

n number;

begin

n := 10;

if n > 10 then

n := 20;

dbms_output.put_line(n);

else

n := 30;

dbms_output.put_line(n);

end if;

if n > 10 then

n := 20;

dbms_output.put_line(n);

end if;

if n > 10 then

n := 20;

dbms_output.put_line(n);

elsif n > 5 then

n := 30;

dbms_output.put_line(n);

else

n := 40;

dbms_output.put_line(n);

end if;

case n

when 10 then

n := 100;

dbms_output.put_line(n);

when 12 then

n := 200;

dbms_output.put_line(n);

else

n := 300;

dbms_output.put_line(n);

end case;

case

when n = 10 then

n := 100;

dbms_output.put_line(n);

when n = 12 then

n := 200;

dbms_output.put_line(n);

else

n := 300;

dbms_output.put_line(n);

end case;

end;

declare

n number := 10;

begin

case n

when 1 then

dbms_output.put_line('1');

when 2 then

dbms_output.put_line('1');

end case;

exception

when case_not_found then

dbms_output.put_line('case not found');

end;

declare

n number;

begin

n := 1;

loop

dbms_output.put_line(n);

n := n+1;

exit when n > 10;

end loop;

end;

declare

n number;

begin

n := 1;

loop

dbms_output.put_line(n);

n := n+1;

if n > 10 then

exit;

end if;

end loop;

end;

declare

n number;

begin

n := 1;

while n <= 10 loop

dbms_output.put_line(n);

n := n+1;

end loop;

end;

declare

n number;

begin

for n in 1..10 loop

dbms_output.put_line(n);

end loop;

end;

declare

n number;

begin

for n in reverse 1..10 loop

dbms_output.put_line(n);

end loop;

end;

Неявное использование переменной цикла

declare

n number := 100;

begin

for n in 1..10 loop

dbms_output.put_line(n);

end loop;

dbms_output.put_line('after ' || n);

end;

declare

n number;

begin

for i in 1..10 loop

n := i;

dbms_output.put_line(n || ' ' || i);

-- error

-- i := 20;

end loop;

dbms_output.put_line(n);

end;

Соседние файлы в папке РСБДтЗ