0% found this document useful (0 votes)
27 views

PLSQL Student Implicit Cursor

The document describes creating a Students Information table to store student registration numbers, names, and marks for 4 subjects. It inserts data for 3 students and adds columns for total marks, grade, and average. It then uses a PL/SQL block with a cursor to calculate these values for each student and update the table. It also shows using an implicit cursor to search for an employee's first and last name based on an ID input.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

PLSQL Student Implicit Cursor

The document describes creating a Students Information table to store student registration numbers, names, and marks for 4 subjects. It inserts data for 3 students and adds columns for total marks, grade, and average. It then uses a PL/SQL block with a cursor to calculate these values for each student and update the table. It also shows using an implicit cursor to search for an employee's first and last name based on an ID input.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Ex.

No:10

Creation of Students Information table and write PL/SQL Block to find the Total, Average
marks and Results.

create table stud333(regno number,name varchar(20),mark1 number,mark2 number(20),mark3

number,mark4 number(20));

insert into stud333 values(001,'gowtham',23,49,44,46);

insert into stud333 values(002,'prasanth',40,30,20,25);

insert into stud333 values(003,'vichu',35,25,45,15);

alter table stud333 add (total number(20),grade varchar(20),aver number(20));

declare

cursor c is select*from stud333;

v_stud1 stud333%rowtype;

grade1 varchar(20);

begin

for v_stud1 in c loop

v_stud1.total:=v_stud1.mark1+v_stud1.mark2+v_stud1.mark3+v_stud1.mark4;

v_stud1.aver:=v_stud1.total/2;

if(v_stud1.aver>90)then

grade1:='A';

elsif (v_stud1.aver>75)then

grade1:='B';

elsif (v_stud1.aver>60)then

grade1:='C';
elsif(v_stud1.aver>50)then

grade1:='D';

else

grade1:='E';

end if;

update stud333 set total=v_stud1.total,grade=grade1,aver=v_stud1.aver where


regno=v_stud1.regno;

end loop;

end;

select*from stud333;

Ex.No:11

Program to demonstrate PL/SQL to show the uses of implicit cursor without using any
attribute.

create table emp12(empid number(20),first_name varchar(20),last_name varchar(20));


insert into emp12 values(111,'shree ','hari');
insert into emp12 values(112,'E','gowtham');
insert into emp12 values(113,'p','prasanth');
declare
emp_firstname varchar(20);
emp_lastname varchar(20);
emp_id number:=&empid;
begin
select first_name,last_name into emp_firstname,emp_lastname from emp12 where empid =
emp_id;
dbms_output.put_line('employee name:'||emp_firstname||' '||
emp_lastname);
exception
when no_data_found then
dbms_output.put_line('there is no employee with id '||emp_id);
end;

You might also like