|Lesson 6||Parameters and functions|
|Objective|| Use parameters and the RETURN command in a function appropriately.|
Parameters Return Command Function
A function by definition returns a value to the calling command by using the RETURN command.
Because of this, it is considered good programming practice to avoid defining OUT or IN OUT parameters with a function.
Use IN mode parameters within a function exclusively, in order to preserve the function's task of returning a single value via the RETURN command (instead of an OUT or IN OUT parameter).
Look at the following Slideshow to see how to change a procedure with an IN and an OUT parameter to a function with and IN parameter and a RETURN command.
You begin with the procedure that was started in the Slideshow in the previous lesson.
Cursors With Parameters
The main reason for using a function instead of a procedure is so that you can use it within a query or other SQL command.
Remember that there are restrictions on what a function can do, so not every procedure can be converted to a function.
The next lesson covers how to use parameters when working with cursors.
Convert Procedure to Function