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

Cursor 6

Cursor execution

Uploaded by

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

Cursor 6

Cursor execution

Uploaded by

rtambe171
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name : Rafiya Faiyaz Tambe

Roll No. : C31101


Division : 1
Batch : T1

Assignment 6
Title: Cursors: (All types: Implicit, Explicit, Cursor FOR Loop,
Parameterized Cursor)

student(roll_no, name, marks)


Problem Statement:

1.Write an anonymous code block which will update marks of students to 40 if he


has scored between 35 to 39. Using implicit cursor parameters show whether any
records have been updated or not. If updated, display how many records have been
updated.

BEGIN

UPDATE student

SET marks = 40

WHERE marks BETWEEN 35 AND 39;

IF sql%notfound THEN

dbms_output.put_line('no recd found');

ELSE

dbms_output.put_line('total row count updated: '||sql%rowcount);

END IF;

END;

Assumed Data in the student table:

r nam mar
ol e ks
l

1
0 Alice 85
1

1
0 Bob 72
2

1
Charl
0 60
ie
3

Assumed Data in the student_copy table before the cursor runs:

r
na mar
ol
me ks
l

1
0 Bob 72
2

2.Write an anonymous code block to demonstrate use of explicit cursor, for loop &
parametrized explicit cursor. Copy the content of student table to another table.
Before copying, check whether second table consists of same roll number record.
If so, discard it otherwise copy it.

DECLARE

CURSOR c_student IS

SELECT roll, name, marks

FROM student;

CURSOR c_check_roll(p_roll student.roll%TYPE) IS

SELECT roll FROM student_copy WHERE roll = p_roll;

v_roll student.roll%TYPE;

v_name student.name%TYPE;
v_marks student.marks%TYPE;

BEGIN

FOR student_rec IN c_student LOOP

OPEN c_check_roll(student_rec.roll);

FETCH c_check_roll INTO v_roll;

IF c_check_roll%FOUND THEN

dbms_output.put_line('yayy found');

ELSE

INSERT INTO student_copy (roll, name, marks)

VALUES (student_rec.roll, student_rec.name, student_rec.marks);

END IF;

CLOSE c_check_roll;

END LOOP;

END;

After Execution, the student_copy table will look like this:

r
nam mar
ol
e ks
l

1
0 Bob 72
2

1
0 Alice 85
1

1
Charl
0 60
ie
3

You might also like