You are on page 1of 3

DBMS Practical

Ques 1 – Consider the following database and display the workers name with the count
of worker having similar names.
Ans - SELECT NAME ,COUNT(*)
FROM Worker
GROUP BY NAME
ORDER BY COUNT(*) DESC,NAME;
Ques 2 – Write a pl/sql program to swap two numbers.
Ans- declare
a number ;
b number;
temp number ;

begin
a:=2;
b:=5;

DBMS_OUTPUT.PUT_LINE('Before swapping : ');


DBMS_OUTPUT.PUT_LINE('a = ' || a);
DBMS_OUTPUT.PUT_LINE('b = ' || b);

temp := a;
a:=b;
b:=temp;

DBMS_OUTPUT.PUT_LINE('After swapping : ');


DBMS_OUTPUT.PUT_LINE('a = '|| a);
DBMS_OUTPUT.PUT_LINE('b = ' || b);
END;
Ques 3 – Consider the following database and display the names of all workers in
descending order.
Ans - SELECT NAME
FROM Worker
ORDER BY NAME DESC;
Ques 4 – Consider the following database and display the worker name who is getting
highest salary.
Ans - SELECT NAME
FROM Worker
WHERE SALARY = (
SELECT MAX(SALARY)
FROM Worker
)
Ques 5 – Write a pl/sql program check and display n=121 is palindrome or not.
Ans - DECLARE
n number := 121;
reversed number := 0;
original number := n;
digit number;

BEGIN

while n>0 loop


digit :=MOD(n,10);
reversed := reversed * 10 +digit;
n := TRUNC(n/10);
end loop;

if original = reversed then


DBMS_OUTPUT.PUT_LINE(original || ' is a palindrome.');
else
DBMS_OUTPUT.PUT_LINE(original || ' is not a palindrome.');
end if ;
end;

You might also like