You are on page 1of 6

DBMS LAB ASSIGNMENT-8

NAME: -Vemula kasinath


REG NO: -20MIA1109

Answer all the Questions:


1. Write a simple PL/SQL Block to print Hello DBMS.

CODE:

BEGIN

dbms_output.put_line ('Hello DBMS');

END;

2. Write a simple PL/SQL block to accept two numbers from user and perform all four basic
mathematical

operations using case statement.

Code :

Declare

V1 integer;

V2 integer;

V3 integer;

V4 integer;

V5 integer;

V6 integer;

Begin

V1:=&v1;

V2:=&v2;

V3:=v1+v2;

V4:=v1-v2;

V5:=v1/v2;

V6:=v1*v2;
DBMS LAB ASSIGNMENT-8
Dbms_output.put_line(v3);

Dbms_output.put_line(v4);

Dbms_output.put_line(v5);

Dbms_output.put_line(v6);

End;

3. Write a simple PL/SQL block to fetch the salary of employee named ‘Ben’ from the Employee table.

CODE:

create table employee_20mia11(empid int,empname varchar(40),job varchar(40),salary int,deptname


char(20),gender char(1));

insert into

employee_20mia11(empid,empname,job,salary,deptname,gender)values(12,'ben','PET
teach',90000,'CSE','M');

insert into

employee_20mia11(empid,empname,job,salary,deptname,gender)values(13,'lucia','english
teach',920000,'CSE','F');

insert into

employee_20mia11(empid,empname,job,salary,deptname,gender)values(14,'gopi','social
teach',30000,'AI','M');

insert into

employee_20mia11(empid,empname,job,salary,deptname,gender)values(51,'yashwant','science
teach',10000,'IT','M');

insert into

employee_20mia11(empid,empname,job,salary,deptname,gender)values(26,'sylive','math
teach',50000,'CSE','F');

DECLARE

v_sal int;

BEGIN

SELECT Salary INTO v_sal FROM employee_20mia11 WHERE empName='ben';


DBMS LAB ASSIGNMENT-8
dbms_output.PUT_LINE('BEN '|| v_sal);

END;

4. Write a simple PL/SQL block to accept the department number from user and print the count of
employees in

that department specified by the user.

CODE:

DECLARE

count1 number(9);

BEGIN

SELECT count(deptname) INTO count1 FROM employee_20mia11 where deptname='CSAI';

dbms_output.put_line('no of CSAI ' || count1);

END;

5. Write a simple PL/SQL block to get the age of a person as input and determine if the person is eligible
for covid

vaccination.

CODE:

DECLARE

v_n1 NUMBER;

BEGIN

v_n1 := 10;

IF v_n1 > 40 THEN

dbms_output.put_line(v_n1 ||' is eligible for vacination');

ELSE
DBMS LAB ASSIGNMENT-8
dbms_output.put_line(v_n1 ||' is not eligible for vacination ');

END IF;

END;

6. Write a simple PL/SQL block to find the greatest of three given numbers.

CODE:

Declare

a number;

b number;

c number;

Begin

dbms_output.put_line('Enter a:');

a:=&a;

dbms_output.put_line('Enter b:');

b:=&b;

dbms_output.put_line('Enter c:');

c:=&C;

if (a>b) and (a>c)

then

dbms_output.put_line('A is GREATEST'||A);

elsif (b>a) and (b>c)

then

dbms_output.put_line('B is GREATEST'||B);

else

dbms_output.put_line('C is GREATEST'||C);

end if;

End;
DBMS LAB ASSIGNMENT-8

7. Write a simple PL/SQL block to get the day of the week as input from user and print the
corresponding day.

1 – SUN and 7-SAT

DECLARE

t_day number:=4;

BEGIN

case t_day

WHEN 1 THEN

dbms_output.Put_line ('The date you entered is Sunday.');

WHEN 2 THEN

dbms_output.Put_line ('The date you entered is Monday.');

WHEN 3 THEN

dbms_output.Put_line ('The date you entered is Tuesday.');

WHEN 4 THEN

dbms_output.Put_line ('The date you entered is Wednesday.');

WHEN 5 THEN

dbms_output.Put_line ('The date you entered is Thursday.');

WHEN 6 THEN

dbms_output.Put_line ('The date you entered is Friday.');

WHEN 7 THEN

dbms_output.Put_line ('The date you entered is Saturday.');

end case;

END;

9. Write a simple PL/SQL block to print the sum of first n natural numbers using for loop.
DBMS LAB ASSIGNMENT-8
CODE:

declare

i integer;

s integer;

begin

s:=0;

for i in 1..3 loop

s:=s+i;

end loop;

dbms_output.put_line('Sum = '||s);

end;

10. Write a simple PL/SQL block to print the sum of first n natural numbers using while loop.

CODE:

DECLARE

num NUMBER:='&Input_Number';

res NUMBER:=0;

BEGIN

WHILE(num>0)LOOP

res:=res+num;

num:=num-1;

EXIT WHEN num=0;

END LOOP;

DBMS_OUTPUT.PUT_LINE(res||' Is Total !');

END;

You might also like