Embed presentation
Download to read offline



![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];](https://image.slidesharecdn.com/function-130902115549-phpapp02/85/Function-4-320.jpg)
![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;](https://image.slidesharecdn.com/function-130902115549-phpapp02/85/Function-5-320.jpg)

A function in PL/SQL is a named code block that returns a value, similar to a procedure but with a mandatory return. Functions have three sections - a declaration section for variables, an executable section containing code to perform a task, and an optional exception handling section. The CREATE FUNCTION syntax identifies the function name, any parameters, the return data type, and the three sections within the BEGIN and END keywords. An example creates a factorial function that returns the factorial of a number passed as a parameter.



![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];](https://image.slidesharecdn.com/function-130902115549-phpapp02/85/Function-4-320.jpg)
![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;](https://image.slidesharecdn.com/function-130902115549-phpapp02/85/Function-5-320.jpg)