This Oracle tutorial explains how to create and drop functions in Oracle/PLSQL with syntax and examples.
Create Function
Just as you can in other languages, you can create your own functions in Oracle.
Syntax
The syntax to create a function in Oracle is:
When you create a procedure or function, you may define parameters. There are three types of parameters that can be declared:
IN - The parameter can be referenced by the procedure or function. The value of the parameter can not be overwritten by the procedure or function.
OUT - The parameter can not be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function.
IN OUT - The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.
Example
Let's look at an example of how to create a function in Oracle.
The following is a simple example of an Oracle function:
This function is called FindCourse. It has one parameter called name_in and it returns a number. The function will return the course number if it finds a match based on course name. Otherwise, it returns a 99999.
You could then reference your new function in a SQL statement as follows:
Drop Function
Once you have created your function in Oracle, you might find that you need to remove it from the database.
Syntax
The syntax to a drop a function in Oracle is:
function_name
The name of the function that you wish to drop.
Example
Let's look at an example of how to drop a function in Oracle.
For example:
This example would drop the function called FindCourse.