Contents
What are the differences between a function and a procedure?
Function is used to calculate something from a given input. Hence it got its name from Mathematics. While procedure is the set of commands, which are executed in a order.
What is difference between function and procedure explain with example?
A function is used to calculate result using given inputs. A procedure is used to perform certain task in order. A function returns a value and control to calling function or code. A procedure returns the control but not any value to calling function or code.
When should you use a function?
A function is almost like a mini-program that we can write separately from the main program, without having to think about the rest of the program while we write it. This allows us to reduce a complicated program into smaller, more manageable chunks, which reduces the overall complexity of our program.
When you should use a function over a procedure?
Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it. Procedures can’t be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.
How do you write a procedure?
Here are some good rules to follow:
- Write actions out in the order in which they happen.
- Avoid too many words.
- Use the active voice.
- Use lists and bullets.
- Don’t be too brief, or you may give up clarity.
- Explain your assumptions, and make sure your assumptions are valid.
- Use jargon and slang carefully.
When using a function what is the first thing you must do?
To create a function, we must first declare it and give it a name, the same way we’d create any variable, and then we follow it by a function definition: var sayHello = function() { }; We could put any code inside that function – one statement, multiple statements – depends on what we want to do.