LOCAL
LOCAL is a qualifier used in SQL within SET TRANSACTION command. It establishes that the scope of the transaction is confined to the current session only. Transactions confined by LOCAL do not impose locks and do not conflict with other transactions. It ensures that the changes made in the session do not interfere with operations outside of the existing session.
Example
Output
Explanation
In the example, SET @location := 'Los Angeles';
is a declaration of a local variable @location
in MySQL. The variable takes the string value ‘Los Angeles’. A SELECT statement is then written to retrieve the names and locations of the employees whose location matches the value of the @location
variable. This variable is local to the session in which it is being executed.
Example
Output
Explanation
In the example, a new transaction is initiated with BEGIN
. Inside this transaction, the SET LOCAL
command is used to modify the timezone
parameter to ‘America/New_York’ only for the duration of the current transaction. The SHOW timezone
command is executed to display the current value of timezone
, which verifies that the change has been made. The transaction is finalized using COMMIT
.
Example
Output
Explanation
In the given example, a local variable var1
was declared and initialized with a value of 30 within a PL/SQL block. This variable was used in an operation to increment its value by 10, and the resultant value of var1
, which is 40, was printed out.