3. Function
What is a Function in PL/SQL?
A function are named PL/SQL Block. It is similar to
a procedure. The major difference between a procedure and a
function is, a function must always return a value, but a
procedure may or may not return a value.
Structure of function
stored functions 3 sections
1.declaration section-declaration of variables and constants
2.executable section-pl/sql statements which perform specific
task
3.exception handling section-the error occuring in executable
part can be handled in this section
4. SYNTAX
CREATE [OR REPLACE] FUNCTION function_name
[ (parameter [,parameter]) ]
RETURN return_datatype
IS | AS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [function_name];
5. Example
CREATE [OR REPLACE] FUNCTION fa(m number)
RETURN number
IS
f number:=1;
BEGIN
for I in 1….m
Loop
F:=f*I;
End loop;
return f;
End;