DBMS 1-5
DBMS 1-5
DBMS 1-5
Theory:
Procedure:
Stored Procedures are created to perform one or more DML operations on Database. It is nothing
but the group of SQL statements that accepts some input in the form of parameters and performs
some task and may or may not returns a value.
1. IN:
This is the Default Parameter for the procedure. It always receives the values from calling
program.
2. OUT:
This parameter always sends the values to the calling program.
3. IN OUT:
This parameter performs both the operations. It receives value from as well as sends the values
to the calling program.
Function:
The CREATE FUNCTION statement is used for creating a stored function and user-defined
functions. A stored function is a set of SQL statements that perform some operation and return a
single value.
Just like Mysql in-built function, it can be called from within a Mysql statement.
By default, the stored function is associated with the default database.
The CREATE FUNCTION statement require CREATE ROUTINE database privilege.
Syntax:
The syntax for CREATE FUNCTION statement in Mysql is:
Mysql Statements
RETURN expression;
END
The function body must contain one RETURN statement.
Application of Procedure and Function:
Procedure Example:
Imagine a table named with emp_table stored in Database. We are Writing a Procedure to update a
Salary of Employee with 1000.
VARIABLE v NUMBER;
PRINT :
Output: 21
Function Example:
Consider following Employee Table-
We have to find the number of years the employee(hospital) has been in the company-
DELIMITER //
END //
DELIMITER ;