<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>local variable &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/local-variable/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Tue, 03 Oct 2017 13:05:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>MySQL: Procedure Variable vs Session specific User Defined Variable (@variable vs variable)</title>
		<link>https://www.dbrnd.com/2016/02/mysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable/</link>
					<comments>https://www.dbrnd.com/2016/02/mysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 17 Feb 2016 19:14:14 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[local variable]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<category><![CDATA[session variable]]></category>
		<category><![CDATA[user defined variable]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1669</guid>

					<description><![CDATA[I found lots of questions and discussions on the difference between stored procedure local variable and session-specific user-defined variable of MySQL. MySQL provides session specific user defined variable to initialize and use during the session. The scope of this variable is for the specific session only and outside of that session another client connection cannot [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable%2F&amp;linkname=MySQL%3A%20Procedure%20Variable%20vs%20Session%20specific%20User%20Defined%20Variable%20%28%40variable%20vs%20variable%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable%2F&amp;linkname=MySQL%3A%20Procedure%20Variable%20vs%20Session%20specific%20User%20Defined%20Variable%20%28%40variable%20vs%20variable%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable%2F&amp;linkname=MySQL%3A%20Procedure%20Variable%20vs%20Session%20specific%20User%20Defined%20Variable%20%28%40variable%20vs%20variable%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable%2F&amp;linkname=MySQL%3A%20Procedure%20Variable%20vs%20Session%20specific%20User%20Defined%20Variable%20%28%40variable%20vs%20variable%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable%2F&amp;linkname=MySQL%3A%20Procedure%20Variable%20vs%20Session%20specific%20User%20Defined%20Variable%20%28%40variable%20vs%20variable%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable%2F&amp;linkname=MySQL%3A%20Procedure%20Variable%20vs%20Session%20specific%20User%20Defined%20Variable%20%28%40variable%20vs%20variable%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable%2F&#038;title=MySQL%3A%20Procedure%20Variable%20vs%20Session%20specific%20User%20Defined%20Variable%20%28%40variable%20vs%20variable%29" data-a2a-url="https://www.dbrnd.com/2016/02/mysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable/" data-a2a-title="MySQL: Procedure Variable vs Session specific User Defined Variable (@variable vs variable)"></a></p><p>I found lots of questions and discussions on the difference between stored procedure local variable and session-specific user-defined variable of MySQL. </p>
<p>MySQL provides session specific user defined variable to initialize and use during the session. </p>
<blockquote><p>The scope of this variable is for the specific session only and outside of that session another client connection cannot access this variable and once session terminates, it destroys automatically. </p></blockquote>
<p>This is loosely typed variables and we can initialize somewhere in a session.<br />
We can write @var_name to define a session specific variable. </p>
<blockquote><p>We also have one local variable, which we can define and use for specific stored objects like a stored procedure.<br />
The scope of this local variable is for that object execution purpose. Once a stored procedure executes, it destroys automatically. </p></blockquote>
<p><strong>Below is a small demonstration on use of @variable vs variable:</strong><br />
<strong>Create a sample stored procedure with session and local variable:</strong> </p>
<pre class="crayon-plain-tag">DELIMITER //
CREATE PROCEDURE usp_TestVariables()
BEGIN
    -- Declare Local Variable.....
    DECLARE MyVariable INT DEFAULT 1;
    SET MyVariable := MyVariable + 1;
    
    -- Define Session Specific Variable.....
    SET @MyVariable := @MyVariable + 1;
    
    SELECT  MyVariable, @MyVariable;
END;

-- Assign value to user defined variable.
SET @MyVariable = 1;</pre> </p>
<pre class="crayon-plain-tag">-- Execute this stored procedure multiple times to check a value of both the variables.
CALL usp_TestVariables();

--The result of first call.
MyVariable    @MyVariable
-----------  ----------------
    2	           2

--The result of second call.
MyVariable    @MyVariable
-----------  ----------------
    2	           3

--The result of third call.
MyVariable    @MyVariable
-----------  ----------------
    2	           4

--The result of fourth call.
MyVariable    @MyVariable
-----------  ----------------
    2	           5</pre> </p>
<p>You can check the above result, where @MyVariable is incrementing because it persists values until session end.<br />
A stored procedure local variable is not incrementing because it destroyed after every execution of the stored procedure. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/mysql-procedure-variable-vs-session-specific-user-defined-variable-variable-vs-variable/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
