rdbms2 (1)
rdbms2 (1)
Problem Sheet 2
1) To write PL/SQL block for inserting rows into EMPDET table with the following calculation:
HRA=50% OF BASIC
DA=20% OF BASIC
PF=7% OF BASIC
NETPAY=BASIC+DA+HRA-PF
BEGIN
VALUES(1000,(1000*50/100),(1000*20/100),(1000*7/100,)(1000+(1000*20/100)+(1000*50/10
0)));
END;
DECLARE
min_number NUMBER;
max_number NUMBER;
BEGIN
SELECT
END;
DECLARE
n NUMBER;
1|P age
2202040601109 RAJAN YADAV
n:=:n;
IF n > 0 THEN
ELSEIF n = 0 THEN
ELSE
ENDIF;
END;
DECLARE
n NUMBER :=:n;
is_odd BOOLEAN;
BEGIN
Is_odd:=n/2=1;
IF is_odd THEN
ELSE
ENDIF;
END;
2|P age
2202040601109 RAJAN YADAV
DECLRE
I INTEGER := 0;J
INTEGER :=1; N
INTEGER :=n;
BEGIN
DBMS_OUTPUT.PUT_LINE(i+j);
I:=j;
J:= i+j;
END LOOP;
END;
DECLARE
n NUMBER;
fact NUMBER;
BEGIN
n:=: n;
fact :=factc*n;
3|P age
2202040601109 RAJAN YADAV
n:= n-1;
END LOOP;
Dbms_output.put_line(fact);
END;
DECLARE
X number :=: x;
Y number :=: y;
Temp number;
BEGIN
Dbms_output.put_line(‘before swapping’);
Dbms_output.put_line(‘X=’||x);
Dbms_output.put_line(‘Y=’||y);
END;
4|P age
2202040601109 RAJAN YADAV
DECLARE
Str_len INTEGER;
BEGIN
Str_len := LENGTH(str);
END:
DECLARE
n NUMBER;
rev NUMBER;
temp NUMBER;
BEGIN
n:=:num;
temp:=n;
rev:=0;
WHILE (n>0)LOOP
N:=n/10;
END LOOP
ELSE
Mrunali Goyani
5|P age
2202040601109 RAJAN YADAV
ELSEIF
END;
DECLARE
n number:=:num;
s number:=0;
r number;
len number;
m:=n;
len:=length(to_char(n));
while n>0
loop
r:= mod(n,10);
s:= s+power(r,len);
n:= trunc(n/10);
end loop;
if m=s
then
else
6|P age
2202040601109 RAJAN YADAV
end if;
end;
11) Write PL/SQL code for count frequency of character in inputted string.
DECLARE
Strlnput VARCHAR(50);
Strchar VARCHAR(1);
Intfreq INT;
BEGIN
Strlnput:=: strlnput;
Strchar:=: strchar;
Intfreq:=:0;
FOR I IN 1..LENGTH(strlnput)
LOOP
IF SUBSTR(strlnput,I,1)=strChar THEN
Intfreq:= intfreq+1;
END IF:
END LOOP;
END;
7|P age
2202040601109 RAJAN YADAV
12) Write PL/SQL code for convert string into uppercase and lopwercase.
DECLARE
Str VARCHAR(50):=:str;
Str_upper VARCHAR(50);
Str_lowre VARCHAR(20);
BEGIN
Str_upper:=UPPER(str);
Str_LOWER:=LOWER(str);
END;
DECLARE
re_num number(10):=0;
rem number(10);
BEGIN
rem := mod(num,10);
rev_num:= (rev_num*10)+rem;
num:=trunc(num/10);
END LOOP
8|P age
2202040601109 RAJAN YADAV
END:
14) Write PL/SQL code for accept two integer from user and perform arithmetic.
DECLARE
num1 number:=:num1;
num2 number:=:num2;
BEGIN
END;
15) Write PL/SQL block that will accept employee number from user and deduct an amount of
Rs.200 from the inputted employee,if he has a salary less than 1000 after salary is deducted,
It display message ‘salary is less than 1000’ the process is to be fired on the employee table
employee(emp_no,name,salary).
Name varchar(250),
Salary numeric(7)
9|P age
2202040601109 RAJAN YADAV
Insert all
DECLARE
Emp_no number;
Salary NUMBER;
BEGIN
Emp_no=:emp_no;
END IF;
END;
16) Write PL/SQL block to calculate the area of circle for a value of radius varying from 4 To 8.
Store the radius and corresponding value of calculated area in table areas.Areas (Radius,
area).
);
DECLARE
area NUMBER;
BEGIN
10 | P a g e
2202040601109 RAJAN YADAV
area :=3.14159*i*I;
END LOOP;
END;
11 | P a g e