0% found this document useful (0 votes)
108 views3 pages

Practical21 DMS

The document contains three PL/SQL programs that demonstrate the use of cursors. The first program displays details of students in the Computer department, the second prints even-numbered records from a student table, and the third counts items in a store table with prices over 10,000. Each program includes the necessary SQL queries and output statements to achieve the desired results.

Uploaded by

nehabamane6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views3 pages

Practical21 DMS

The document contains three PL/SQL programs that demonstrate the use of cursors. The first program displays details of students in the Computer department, the second prints even-numbered records from a student table, and the third counts items in a store table with prices over 10,000. Each program includes the necessary SQL queries and output statements to achieve the desired results.

Uploaded by

nehabamane6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

a.

Write a PL/SQL program for displaying details of students studying in computer


department using cursors.

Create Following students table:

student_id student_name department


101 Arya Computer
102 Nisha Mathematics
103 Rahul Computer
104 David Physics
105 Raj Computer

Set serveroutput on;

DECLARE
CURSOR student_cursor IS
SELECT student_id, student_name, department
FROM students
WHERE department = 'Computer';
v_student_id students.student_id%TYPE;
v_student_name students.student_name%TYPE;
v_department [Link]%TYPE;
BEGIN
OPEN student_cursor;
LOOP
FETCH student_cursor INTO v_student_id, v_student_name, v_department;
EXIT WHEN student_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Student ID: ' || v_student_id ||', Name: ' || v_student_name ||
', Department: ' || v_department);
END LOOP;
CLOSE student_cursor;
END;
/
b. Write a PL/SQL program to print even number of records stored in the student table.

Create Following Student Table


student_id student_name
1 Aditya
2 Babita
3 Charu
4 David
5 Esha
6 Rahul

DECLARE
CURSOR c_student IS
SELECT *
FROM student
ORDER BY student_id;
v_row_number NUMBER := 0;
v_student_id student.student_id%TYPE;
v_student_name student.student_name%TYPE;
BEGIN
OPEN c_student;
LOOP
FETCH c_student INTO v_student_id, v_student_name, ...;
EXIT WHEN c_student%NOTFOUND;
v_row_number := v_row_number + 1;
IF MOD(v_row_number, 2) = 0 THEN
DBMS_OUTPUT.PUT_LINE('Student ID: ' || v_student_id || ', Name: ' || v_student_name ||
' ...');
END IF;
END LOOP;
CLOSE c_student;
END;
/
C. Write a PL/SQL program to display the number of items having price more than 10000 in store
table using cursors.

Create following store table:

item_id item_name price


1 Laptop 12000
2 Mouse 500
3 Printer 15000
4 Monitor 9500
5 Keyboard 18000

DECLARE
CURSOR c_store IS
SELECT *
FROM store
WHERE price > 10000;
v_count NUMBER := 0;
BEGIN
OPEN c_store;
LOOP
FETCH c_store INTO v_item_id, v_item_name, v_price; -- Fetch necessary columns
EXIT WHEN c_store%NOTFOUND;
v_count := v_count + 1;
END LOOP;
CLOSE c_store;
DBMS_OUTPUT.PUT_LINE('Number of items with price > 10000: ' || v_count);
END;
/

You might also like