Variables
This lesson sheds light on how to declare and use variables in a stored procedure and also discusses the scope of variables.
Variables
A variable is nothing but a data object with a name associated to it. Variables help store a user-defined, temporary value which can be referred to in subsequent statements.
A variable must be declared before it can be used in the code. The DECLARE keyword is used to declare variables by providing the data type and an optional default value. If DEFAULT is not used at the time of declaration, then the variable will have NULL value.
Assignment of a value to a variable is done using the SET keyword. Another way to assign values to a variable is to use it in a query with a SELECT INTO statement.
The scope of a variable defines its lifetime after which it becomes unavailable. The scope of a variable created in a stored procedure is local meaning that it will not ...