Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

EXPERIMENT NO:-6

5.1 Write a PL/SQL code block to find total and average of 6 subjects and display the

grade.

Ans:-

DECLARE

a INT;

b INT;

c INT;

FUNCTION sumOF(x IN INT, y IN INT)

RETURN INT IS z INT;

BEGIN

z:= x+y;

RETURN z;

END;

BEGIN

a:= &x1;

b:= &x1;

c := sumOF(a, b);

dbms_output.put_line(' sum of (a,b): ' || c);

END;

/
5.2 Write a PLSQL code block to accept table name and display number of rows in a table.

Ans:- DECLARE
num number;
reverse number;
FUNCTION reversenum(num1 number) RETURN number IS rev number;
num2 number;
num3 number;

BEGIN
rev:=0;
num3:=num1;
while num3>0
loop
num2:=num3 mod 10;
rev:=num2+(rev*10);
num3:=trunc(num3/10);
end loop;
RETURN rev;
END;
BEGIN
num:= #
reverse := reversenum (num);
dbms_output.put_line(' Reverse of '|| num || ' is ' || reverse);
END;

6.3. Write a PL/SQL procedure to calculate the sum of first N number where N is passed as parameter.

Ans:- DECLARE
num number;
sum2 number;

FUNCTION naturalsum(num1 number) RETURN number IS sum1 number;


begin
Sum1:=num1*(num1+1)/2;

RETURN sum1;
END;
BEGIN
num:= #
dbms_output.put_line(num);

sum2 := naturalsum (num);


dbms_output.put_line('sum of '||num||' natural number ' ||sum2);
END;

6.4. Write a PL/SQL function that accepts department number and returns the total salary of the
department. Use table EMPLOYEES(as given in Experiment 1- Q.6)

Ans:-

You might also like