|
|
Notes 0012FunctionsFunctions are special types of procedures that have the capability to return a value. It is a very shady question of when to use what, either functions or procedures. A good rule of thumb is: if you're interested in the "results" of the code, then you use a function, and return those results. If you're interested in the "side effects" (like table updates, etc.) and not about the "result" when you should use a procedure. Usually it doesn't affect your code all that much if you use a procedure or a function. General FormatThe general format of a function is very similar to the general format of a procedure:
For example, to write a function that computes the sum of two numbers, you might do something like this:
To run it, we'll write a small piece of code that calls this:
Which procudes the output: RESULT IS: 46 All of a sudden, we know how to make functions (since we already know how to crate procedures). That's really all there is to it. Dropping FunctionsTo drop a function, you do it in a similar way to a procedure. You simply say: DROP FUNCTION function_name; Oh, btw, to display the list of procedures/functions or plain general user objects that you have you can run a query:
You can do a similar thing for procedures. That's all there is to stored procedures and functions! You should practice writing these things. There is no better way to learn these than to do it yourself and get familiar with all the concepts and code.
|