Ass 1
Ass 1
Set A:
2. Write a PL/SQL block which will accept student details, calculate the
class using per value and insert the record into Student(rno, sname,
class, per, class) table.
create table student (rno number, sname varchar(20),percen number(2,2),clas
varchar(20));
select * from student;
Declare
rno number;
sname varchar(20);
p number;
sclass varchar(20);
Begin
rno:=1;
sname:='seema';
p:=70;
if(p>=75) then
sclass:='distinction';
elsif(p>=60) then
sclass:='first class';
elsif(p>=50) then
sclass:='second class';
elsif(p>=40) then
sclass:='pass class';
else
sclass:='fail';
end if;
insert into student values(rno,sname,p,sclass);
DBMS_OUTPUT.PUT_LINE('Record inserted successfully');
end;
3. Write a PL/SQL block which will accept two numbers from user, check
whether numbers are positive or negative. If positive number then
display only the odd numbers between the entered numbers.
Declare
no1 number;
no2 number;
d2 number;
d1 number;
Begin
no1:=34;
no2:=23;
if ((no1>0) and (no2>0)) then
DBMS_OUTPUT.PUT_LINE('Numbers are positive');
d1:=no1 mod 2;
d2:=no2 mod 2;
if(d1 <> 0) then
DBMS_OUTPUT.PUT_LINE(no1);
end if;
if(d2 <> 0) then
DBMS_OUTPUT.PUT_LINE(no2);
end if;
else
DBMS_OUTPUT.PUT_LINE('Numbers are Negative');
end if;
end;
Set B:
1. Write a PL/SQL block which will accept roll number of a student and
display record of student from student table( use %ROWTYPE
attribute)
CREATE TABLE STUDENT1 (
rno number ,
sname VARCHAR(15) NOT NULL,
age INT NOT NULL,
percen INT NOT NULL,
PRIMARY KEY (rno)
);
Declare
stud student1%ROWTYPE;
no1 student.rno%TYPE;
Begin
no1:=1;
select * into stud from student1 where rno=no1;
DBMS_OUTPUT.PUT_LINE('Roll NO=' || stud.rno);
DBMS_OUTPUT.PUT_LINE('Name=' || stud.sname);
DBMS_OUTPUT.PUT_LINE('Age=' || stud.age);
DBMS_OUTPUT.PUT_LINE('Percentage=' || stud.percen);
end;
2. Write a PL/SQL block which will accept roll number from student,
select name and percentage of student and calculate grade using
percentage value. Display the record. (use %TYPE)
Declare
stud student1%ROWTYPE;
no1 student1.rno%TYPE;
p student1.percen%TYPE;
grade varchar(20);
Begin
no1:=1;
select * into stud from student1 where rno=no1;
p:=stud.percen;
if(p>=75) then
grade:='distinction';
elsif(p>=60) then
grade:='first class';
elsif(p>=50) then
grade:='second class';
elsif(p>=40) then
grade:='pass class';
else
grade:='fail';
end if;
3.