Aniqlanmagan kursor bilan ishlash BEGIN
FOR i IN (SELECT * FROM student1 WHERE id_group = '2')
LOOP
DBMS_OUTPUT.PUT_LINE(i.name||chr(9)||i.id_group);
END LOOP;
END;
Dasturlashda qism dastur tushunchasi mavjud bo‘lib, u dasturning bir
qismini bajarilishini o‘z zimmasiga oladi. O‘z navbatida bitta katta dastur
ana shunday qism dasturlardan tashkil topishi mumkin. Qism dasturlar
dastur ishlash jarayonida murojaat qilinishi natijasida faollashadi, biror
qiymatlarni qabul qilishi va qayta ishlab, keyingi qism dasturga uzatishi
mumkin. PL/SQL da qism dasturlar ikki xil bo‘ladi: protsedura va funksiya.
PL/SQL da protseduralar bilan ishlash. CREATE [OR REPLACE] PROCEDURE procedure_name
[(parameter_name [IN | OUT | IN OUT] type [, ...])]
{IS | AS}
BEGIN
< procedure_body >
END procedure_name;
Misol. CREATE OR REPLACE PROCEDURE greetings
AS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World!');
END;
/
Protsedurani chaqirish Protseduraga ikki xil usulda murojaat qilish mumkin:
Execute kalit so‘zi orqali;
PL/SQL bloki yordamida.
Yuqorida keltirilgan protsedura nomi “greatings” bo‘lganligi
sababli
EXECUTE greetings; orqali murojaat qilinadi.
PL/SQL blok orqali murojaat qilishi uchun esa,
BEGIN greetings; END; Ikkala usulda ham bitta javob olamiz:
Hello World
PL/SQL procedure successfully completed.
Protsedurani o‘chirish
DROP PROCEDURE procedure–name; Yuqoridagi protsedurani o‘chirish
DROP PROCEDURE greetings; Parametrli protseduralardan foydalanish
Misol. Ikkita sondan kattasini aniqlash protsedurasi
DECLARE
a number;
b number;
c number;
PROCEDURE findMin(x IN number, y IN number, z OUT number) IS
BEGIN
IF x < y THEN
z:= x;
ELSE
z:= y;
END IF;
END;
BEGIN
a:= 23;
b:= 45;
findMin(a, b, c);
DBMS_OUTPUT.PUT_LINE(' Minimum of (23, 45) : ' || c);
END;