0% found this document useful (0 votes)
8 views2 pages

9th WEEK DBMS

The document outlines the creation of stored functions in SQL for calculating the square of a number, the addition of two numbers, and the area of a rectangle. It includes examples of function definitions, their outputs, and how to call these functions. The results demonstrate successful execution of the functions with provided inputs.

Uploaded by

jahnavisindhu673
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

9th WEEK DBMS

The document outlines the creation of stored functions in SQL for calculating the square of a number, the addition of two numbers, and the area of a rectangle. It includes examples of function definitions, their outputs, and how to call these functions. The results demonstrate successful execution of the functions with provided inputs.

Uploaded by

jahnavisindhu673
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exp No:

Date: Page No:

WEEK-9
Program:
Write a stored function to find square of a given number
SQL> set serveroutput on;
SQL> create function sq(x in number)
2 return number
3 as
4 begin
5 return(x*x);
6 end;
7/
Output:
Function created.
SQL> begin
2 dbms_output.put_line(sq(7));
3 end;
4/
Output 1:
49
PL/SQL procedure successfully completed.
SQL> select sq(8) from dual;
Output 2:
SQ(8)
----------
64
Write a stored function to find addition of two numbers
SQL> create function add_c(a in number, b in number)
2 return number
3 as
4 c number;
5 begin
6 c:=a+b;
7 return c;
8 end;
9/
Output:
Function created.
SQL> declare
2 d number;
3 begin

ADITYA UNIVERSITY (Formerly Aditya Engineering College (A)) ROLL NO: 23A91A0589
Exp No:
Date: Page No:

4 d:=add_c(2,7);
5 dbms_output.put_line(d);
6 end;
7/
Output 1:
9
PL/SQL procedure successfully completed.
SQL> select add_c(3,4) from dual;
Output 2:
ADD_C(3,4)
----------
7
Write a stored function to find area of a rectangle
SQL> create function area_rect(l in number,b in number)
2 return number
3 as
4 area number;
5 begin
6 area:=l*b;
7 return area;
8 end;
9/
Output:
Function created.
SQL> select area_rect(2,7) from dual;
Output 1:
AREA_RECT(2,7)
--------------
14
SQL> declare
2 area_rec number;
3 begin
4 area_rec:=area_rect(2,7);
5 dbms_output.put_line(area_rec);
6 end;
7/
Output 2:
14
PL/SQL procedure successfully completed.

ADITYA UNIVERSITY (Formerly Aditya Engineering College (A)) ROLL NO: 23A91A0589

You might also like