Professional Documents
Culture Documents
CODE:
BEGIN
END;
2. Write a simple PL/SQL block to accept two numbers from user and perform all four basic
mathematical
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:
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
END;
4. Write a simple PL/SQL block to accept the department number from user and print the count of
employees in
CODE:
DECLARE
count1 number(9);
BEGIN
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;
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;
then
dbms_output.put_line('A is GREATEST'||A);
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.
DECLARE
t_day number:=4;
BEGIN
case t_day
WHEN 1 THEN
WHEN 2 THEN
WHEN 3 THEN
WHEN 4 THEN
WHEN 5 THEN
WHEN 6 THEN
WHEN 7 THEN
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;
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;
END LOOP;
END;