Ishdan maqsad: Ma’lumotlar bazasining infologik va mantiqiy modelini, er diagrammalarini yaratishni o‘rganish. Topshiriqlar


Download 1.49 Mb.
bet48/57
Sana27.01.2023
Hajmi1.49 Mb.
#1132339
1   ...   44   45   46   47   48   49   50   51   ...   57
Bog'liq
2 5375303174699622638

DBMS_OUTPUT.put_line(v_empno ||' '|| v_name);
END LOOP;
CLOSE empcur;
–––4: kursorni yopish
END;
Misol–2
Declare
CURSOR cur(gr NUMBER :=20) IS
SELECT * FROM student1 WHERE id_group = gr; i cur%ROWTYPE; BEGIN
OPEN cur(2);
LOOP
FETCH cur INTO i;
EXIT WHEN cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(i.name||chr(9)||i.id_group);
END LOOP;
CLOSE students;
END;
Natija:
Axmedov 2 Azimov 2
Misol–3. Guruh nomiga ko‘ra guruh talabalari haqidagi ma’lumotlarni aniqlovchi kursor yarating.
Bu misolda guruh va talabalar jadvalidan ma’lumotlarni olish talab etilmoqda. Ikkala jadvaldan ma’lumot olib kursor yaratish uchun avval ushbu ikktala jadvaldan ma’lumotlarni o‘qib oluvchi ko‘rinish (view) yaratishimiz zarur. Bu bizga natijada bitta virtual jadval asosida kursor yaratish imkonini beradi.
CREATE VIEW v_student AS
SELECT student1.name, groups.name AS gr_name
FROM student1, groups
WHERE student1.id_group = groups.id_group
SELECT * FROM v_student
Natija:

Kursorni yaratish:
DECLARE
Cursor students(gr VARCHAR2) IS
SELECT * FROM v_student WHERE gr_name = gr; i students%ROWTYPE;
––kursorning har bir satri uchun %ROW tipidan foydalanildi
BEGIN
OPEN students('AT–30');
LOOP
FETCH students into i;
EXIT WHEN students%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(i.name||chr(9)||i.gr_name);
END LOOP;
CLOSE students;
END;
Kursorni FOR operatori bilan qo‘llash:
Declare
CURSOR cur2(gr NUMBER :=2) IS
SELECT * FROM student1 WHERE id_group = gr;
BEGIN
FOR i IN cur2(2) LOOP
DBMS_OUTPUT.PUT_LINE(i.name||chr(9)||i.id_group);
END LOOP;
END;

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.

Download 1.49 Mb.

Do'stlaringiz bilan baham:
1   ...   44   45   46   47   48   49   50   51   ...   57




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling