100% found this document useful (1 vote)
451 views3 pages

Experiment No:-6: 5.1 Write A PL/SQL Code Block To Find Total and Average of 6 Subjects and Display The Grade. Ans

The document contains examples of PL/SQL code blocks and procedures: 1) A code block that finds the total and average of 6 subjects and displays the grade. 2) A code block that accepts a table name and displays the number of rows in the table. 3) A procedure that calculates the sum of the first N numbers where N is passed as a parameter. 4) A function that accepts a department number and returns the total salary of that department by accessing data from the EMPLOYEES table.

Uploaded by

shinigami0000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
451 views3 pages

Experiment No:-6: 5.1 Write A PL/SQL Code Block To Find Total and Average of 6 Subjects and Display The Grade. Ans

The document contains examples of PL/SQL code blocks and procedures: 1) A code block that finds the total and average of 6 subjects and displays the grade. 2) A code block that accepts a table name and displays the number of rows in the table. 3) A procedure that calculates the sum of the first N numbers where N is passed as a parameter. 4) A function that accepts a department number and returns the total salary of that department by accessing data from the EMPLOYEES table.

Uploaded by

shinigami0000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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