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

functions in dbms

DBMS COMMANDS TO CREATE FUNCTIONS

Uploaded by

cseboys2026
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
0% found this document useful (0 votes)
0 views2 pages

functions in dbms

DBMS COMMANDS TO CREATE FUNCTIONS

Uploaded by

cseboys2026
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/ 2

CREATE OR REPLACE FUNCTION FUN (A NUMBER)

RETURN NUMBER IS
BEGIN
RETURN (A*A);
END FUN;

DECLARE
X NUMBER:=:X;
S NUMBER;
BEGIN
S:=FUN(X);
DBMS_OUTPUT.PUT_LINE('SQUARE OF A NUMBER '|| S);
END;
/

functions:
A function is a self contained block that carries out a specific well defined task.

it is enclosed by
{
------
------
}

advantages:
(1) resusability:
i.e, a function may be used by many other programmers once if you declare a function
that function called by many other programmers.
(2) The length of source programme can be reduce:
every you are writing the same function it is increase the source progrmme code
the code of the programme will be increase so for that you can write a function and you can
save the function in one of the file.so you just call the function name it reduces the lenght of
the source programme.

-> function should be declared and defined


before calling so with out declare and define you can not call the function.

so first you want to give the name suppose if you want to call any person
how you will call? with the help of his name you just calling that person by announcing his
name.

if you want to call a function it should be first declared and define before calling.

->A Function is a named pl/sql block like procedure.


->it accepts parameters and be invoked
->A function is mainly used to compute a value.

A function have a return class

-> functions can be stored in the database as a schema object.


->reusability and maintainability.

Basic Syntax of PL/SQL


DECLARE (optional)
/* Variables can be declared here */
BEGIN
/* Executable statements can be written here */
EXCEPTION(optional)
/* Error handlers can be written here.*/
END;

You might also like