Experiment No:-6: 5.1 Write A PL/SQL Code Block To Find Total and Average of 6 Subjects and Display The Grade. Ans
Experiment No:-6: 5.1 Write A PL/SQL Code Block To Find Total and Average of 6 Subjects and Display The Grade. Ans
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;
BEGIN
z:= x+y;
RETURN z;
END;
BEGIN
a:= &x1;
b:= &x1;
c := sumOF(a, b);
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;
RETURN sum1;
END;
BEGIN
num:= #
dbms_output.put_line(num);
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:-