0% found this document useful (0 votes)
20 views4 pages

Ass 1

The document contains 6 PL/SQL program examples: 1. A program that accepts a number from the user and displays its multiplication table from 1 to 10. 2. A program that accepts student details like roll number, name, percentage, calculates the class based on percentage, and inserts the record into a table. 3. A program that accepts two numbers, checks if they are positive or negative, and displays the odd numbers between them if positive. The remaining programs are in Set B: 4. A program that accepts a roll number and displays the record of the student from a table using %ROWTYPE attribute. 5. A program that accepts a roll number, selects the

Uploaded by

Galaxy Knowledge
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)
20 views4 pages

Ass 1

The document contains 6 PL/SQL program examples: 1. A program that accepts a number from the user and displays its multiplication table from 1 to 10. 2. A program that accepts student details like roll number, name, percentage, calculates the class based on percentage, and inserts the record into a table. 3. A program that accepts two numbers, checks if they are positive or negative, and displays the odd numbers between them if positive. The remaining programs are in Set B: 4. A program that accepts a roll number and displays the record of the student from a table using %ROWTYPE attribute. 5. A program that accepts a roll number, selects the

Uploaded by

Galaxy Knowledge
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/ 4

Assignment 1

Set A:

1. Write a pl/sql block to accept a number and display multiplication table


of the given number.
declare
num number:= 5;
i int;
begin
i:=1;
loop
dbms_output.put_line(num*i);
i:=i+1;
exit when i>10;
end loop;
end;
/

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)
);

INSERT INTO STUDENT1 VALUES (1, 'Sameer', 14, 95);


INSERT INTO STUDENT1 VALUES (2, 'Ram', 15, 94);
INSERT INTO STUDENT1 VALUES (3, 'Seema', 14, 100);

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;

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);
DBMS_OUTPUT.PUT_LINE('Grade=' || grade);
end;

3.

You might also like