{"id":525,"date":"2009-12-27T13:18:20","date_gmt":"2009-12-27T13:18:20","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=525"},"modified":"2023-12-27T17:35:04","modified_gmt":"2023-12-28T00:35:04","slug":"variables-in-stored-procedures","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/","title":{"rendered":"MySQL Stored Procedure Variables"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn about MySQL stored procedure&#8217;s variables including how to declare and use them.<\/p>\n\n\n\n<p>A variable is a named data object whose value can change during the execution of a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/\">stored procedure<\/a>. <\/p>\n\n\n\n<p>Typically, you use variables to hold immediate results. These variables are local to the stored procedure. <\/p>\n\n\n\n<p>Before using a variable, you need to declare it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Declaring variables<\/h2>\n\n\n\n<p>To declare a variable inside a stored procedure, you use the <code>DECLARE<\/code> &nbsp;statement as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> variable_name datatype(<span class=\"hljs-keyword\">size<\/span>) &#91;<span class=\"hljs-keyword\">DEFAULT<\/span> default_value];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, specify the name of the variable after the <code>DECLARE<\/code> keyword. Ensure the variable name adheres to MySQL table column naming rules.<\/li>\n\n\n\n<li>Second, define the data type and length of the variable. Variables can have any <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-data-types\/\">MySQL data type<\/a>, such as <code>INT<\/code>, <code>VARCHAR<\/code> , and&nbsp;<code>DATETIME<\/code>.<\/li>\n\n\n\n<li>Third, assign a default value to the variable using the <code>DEFAULT<\/code> option. If you declare a variable without specifying a default value, its default value is <code>NULL<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>The following example declares a variable named <code>totalSale<\/code> with the data type <code>DEC(10,2)<\/code> and default value of <code>0.0<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> totalSale <span class=\"hljs-built_in\">DEC<\/span>(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0.0<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>MySQL allows you to declare two or more variables that share the same data type using a single <code>DECLARE<\/code> statement. <\/p>\n\n\n\n<p>For example, the following example declares two integer variables <code>totalQty <\/code>and&nbsp;<code>stockCount<\/code>, and sets their default values to zero.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> totalQty, stockCount <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>After declaring a variable, you can start using it.<\/p>\n\n\n\n<p>As of MySQL 8.0.34, it is not possible to declare multiple variables with different data types using a single DECLARE statement. <\/p>\n\n\n\n<p>For example, the following declaration will cause a syntax error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">DECLARE<\/span> amount DECMIAL(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>), \n        currency CHAR(<span class=\"hljs-number\">3<\/span>) <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-string\">'USD'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To fix the error, you need to use multiple <code>DECLARE<\/code> statements as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">DECLARE<\/span> amount DECMIAL(<span class=\"hljs-number\">10<\/span>,<span class=\"hljs-number\">2<\/span>);\n<span class=\"hljs-keyword\">DECLARE<\/span> currency CHAR(<span class=\"hljs-number\">3<\/span>) <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-string\">'USD'<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Assigning variables<\/h2>\n\n\n\n<p>To assign a variable a value, you use the <code>SET<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SET<\/span> variable_name = <span class=\"hljs-keyword\">value<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> total <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span>;\n<span class=\"hljs-keyword\">SET<\/span> total = <span class=\"hljs-number\">10<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The value of the <code>total<\/code> variable is <code>10<\/code> &nbsp;after the assignment.<\/p>\n\n\n\n<p>In addition to the <code>SET<\/code>&nbsp;statement, you can use the&nbsp;<code>SELECT INTO<\/code> statement to assign the result of a query to a variable as shown in the following example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> productCount <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span>;\n\n<span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">COUNT<\/span>(*) \n<span class=\"hljs-keyword\">INTO<\/span> productCount\n<span class=\"hljs-keyword\">FROM<\/span> products;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, declare a variable named <code>productCount<\/code> and initialize its value to <code>0<\/code>.<\/li>\n\n\n\n<li>Then, use the <code>SELECT INTO<\/code> statement to assign the <code>productCount<\/code> variable the number of products selected from the <code>products<\/code> table.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Variable scopes<\/h2>\n\n\n\n<p>A variable has its own scope, which determines its lifetime. If you declare a variable inside a stored procedure, it will be out of scope when the <code>END<\/code> statement of the stored procedure is reached.<\/p>\n\n\n\n<p>When you declare a variable inside the <code>BEGIN...END<\/code> block, it goes out of scope once the <code>END<\/code> is reached.<\/p>\n\n\n\n<p>MySQL allows you to declare two or more variables that share the same name in different scopes because a variable is only effective within its scope. <\/p>\n\n\n\n<p>However, declaring variables with the same name in different scopes is not considered good programming practice.<\/p>\n\n\n\n<p>A variable whose name begins with the <code>@<\/code> sign is a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-administration\/mysql-session-variables\/\">session variable<\/a>, available and accessible until the session ends.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL Stored Procedure Variable Example<\/h2>\n\n\n\n<p>The following example illustrates how to declare and use a variable in a stored procedure:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">DELIMITER $$\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">PROCEDURE<\/span> GetTotalOrder()\n<span class=\"hljs-keyword\">BEGIN<\/span>\n\t<span class=\"hljs-keyword\">DECLARE<\/span> totalOrder <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span>;\n    \n\t<span class=\"hljs-keyword\">SELECT<\/span> \n\t\t<span class=\"hljs-keyword\">COUNT<\/span>(*)\n\t<span class=\"hljs-keyword\">INTO<\/span> totalOrder <span class=\"hljs-keyword\">FROM<\/span>\n\t\torders;\n    \n\t<span class=\"hljs-keyword\">SELECT<\/span> totalOrder;\n<span class=\"hljs-keyword\">END<\/span>$$\n\nDELIMITER ;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How it works.<\/p>\n\n\n\n<p>First, declare a variable <code>totalOrder<\/code> with a default value of zero. This variable will store the number of orders from the <code>orders<\/code> table.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">DECLARE<\/span> totalOrder <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, use the <code>SELECT INTO<\/code>&nbsp; statement to assign the variable <code>totalOrder<\/code> the number of orders selected from the <code>orders<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">COUNT<\/span>(*) \n<span class=\"hljs-keyword\">INTO<\/span> totalOrder \n<span class=\"hljs-keyword\">FROM<\/span> orders;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, select the value of the&nbsp;variable <code>totalOrder<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> totalOrder;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"note\">Note that you will learn how to use variables practically in the subsequent tutorials. The example in this tutorial serves as an illustration to help you understand the concept.<\/p>\n\n\n\n<p>This statement calls the stored procedure <code>GetTotalOrder()<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CALL<\/span> GetTotalOrder();<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"93\" height=\"37\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/MySQL-Stored-Procedure-Variable-Output.png\" alt=\"\" class=\"wp-image-8287\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use variables to hold immediate results in a stored procedure.<\/li>\n\n\n\n<li>The scope of a variable determines the variable&#8217;s lifetime.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"525\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/\"\n\t\t\t\tdata-post-title=\"MySQL Stored Procedure Variables\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"525\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/\"\n\t\t\t\tdata-post-title=\"MySQL Stored Procedure Variables\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>You will learn about variables in MySQL stored procedure, how to declare and use the variables. In addition, scope of variable is also covered<\/p>\n","protected":false},"author":2,"featured_media":250,"parent":518,"menu_order":6,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-525","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL Stored Procedure Variables<\/title>\n<meta name=\"description\" content=\"This tutorial introduces you to MySQL stored procedure variables and shows you how to declare and use the variables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Stored Procedure Variables\" \/>\n<meta property=\"og:description\" content=\"This tutorial introduces you to MySQL stored procedure variables and shows you how to declare and use the variables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-28T00:35:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/01\/code_1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"110\" \/>\n\t<meta property=\"og:image:height\" content=\"73\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/\",\"name\":\"MySQL Stored Procedure Variables\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2013\\\/01\\\/code_1.jpg\",\"datePublished\":\"2009-12-27T13:18:20+00:00\",\"dateModified\":\"2023-12-28T00:35:04+00:00\",\"description\":\"This tutorial introduces you to MySQL stored procedure variables and shows you how to declare and use the variables.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2013\\\/01\\\/code_1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2013\\\/01\\\/code_1.jpg\",\"width\":110,\"height\":73},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/variables-in-stored-procedures\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Stored Procedures\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL Stored Procedure Variables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL Stored Procedure Variables","description":"This tutorial introduces you to MySQL stored procedure variables and shows you how to declare and use the variables.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Stored Procedure Variables","og_description":"This tutorial introduces you to MySQL stored procedure variables and shows you how to declare and use the variables.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-12-28T00:35:04+00:00","og_image":[{"width":110,"height":73,"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/01\/code_1.jpg","type":"image\/jpeg"}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/","url":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/","name":"MySQL Stored Procedure Variables","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/01\/code_1.jpg","datePublished":"2009-12-27T13:18:20+00:00","dateModified":"2023-12-28T00:35:04+00:00","description":"This tutorial introduces you to MySQL stored procedure variables and shows you how to declare and use the variables.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/01\/code_1.jpg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/01\/code_1.jpg","width":110,"height":73},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/variables-in-stored-procedures\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Stored Procedures","item":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/"},{"@type":"ListItem","position":3,"name":"MySQL Stored Procedure Variables"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/525\/revisions"}],"predecessor-version":[{"id":13583,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/525\/revisions\/13583"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/518"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media\/250"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}