{"id":12672,"date":"2023-12-02T07:24:26","date_gmt":"2023-12-02T14:24:26","guid":{"rendered":"https:\/\/www.mysqltutorial.org\/?page_id=12672"},"modified":"2023-12-02T07:27:29","modified_gmt":"2023-12-02T14:27:29","slug":"mysql-declare-condition","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/","title":{"rendered":"MySQL DECLARE &#8230; CONDITION Statement"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use MySQL <code>DECLARE ... CONDITION<\/code> statement to declare a named error condition.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL DECLARE &#8230; CONDITION statement<\/h2>\n\n\n\n<p>A condition is a warning or error that occurs within a stored procedure. MySQL uses an error code or an <code>SQLSTATE<\/code> value to represent a condition. However, the error code or <code>SQLSTATE<\/code> may not be clear.<\/p>\n\n\n\n<p>To address this issue, MySQL provides the <code>DECLARE ... CONDITION<\/code> statement to declare a named error condition that associates a name with a condition. <\/p>\n\n\n\n<p>Here&#8217;s the syntax of the <code>DECLARE ... CONDITION<\/code> statement:<\/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> condition_name CONDITION <span class=\"hljs-keyword\">FOR<\/span> condition_value\n\ncondition_value: {\n    mysql_error_code\n  | <span class=\"hljs-keyword\">SQLSTATE<\/span> &#91;<span class=\"hljs-keyword\">VALUE<\/span>] sqlstate_value\n}<\/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 condition&#8217;s name after the <code>DECLARE<\/code> keyword (<code>codition_name<\/code>).<\/li>\n\n\n\n<li>Second, provide the condition value (<code>condition_value<\/code>) after the <code>FOR<\/code> keyword. The condition value can be a MySQL error code or a <code>SQLSTATE<\/code> value.<\/li>\n<\/ul>\n\n\n\n<p class=\"note\">Note that you should not use MySQL error code <code>0<\/code> or <code>SQLSTATE<\/code> value that begins with <code>'00'<\/code> because these indicate success rather than a warning or an error condition.<\/p>\n\n\n\n<p>The named conditions make your store procedures code clearer and easier to maintain.<\/p>\n\n\n\n<p>For example, the following declares a <code>HANDLER<\/code> for the MySQL error code <code>1051<\/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> CONTINUE <span class=\"hljs-keyword\">HANDLER<\/span> <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-number\">1051<\/span>\n  <span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-comment\">-- body of handler<\/span>\n  <span class=\"hljs-keyword\">END<\/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>But 1015 doesn&#8217;t tell its meaning explicitly. To understand it, you need to look it up and find out its meaning, which is &#8220;unknown table&#8221;.<\/p>\n\n\n\n<p>By using a named condition, the code expresses its intent very clearly. For example:<\/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> unknown_table CONDITION <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-number\">1051<\/span>;\n<span class=\"hljs-keyword\">DECLARE<\/span> CONTINUE <span class=\"hljs-keyword\">HANDLER<\/span> <span class=\"hljs-keyword\">FOR<\/span> unknown_table \n  <span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-comment\">-- body of handler<\/span>\n  <span class=\"hljs-keyword\">END<\/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<h2 class=\"wp-block-heading\">MySQL DECLARE&#8230;CONDITION example<\/h2>\n\n\n\n<p>The following example shows how to use the <code>DECLARE ... CONDITION<\/code> to create a stored procedure that retrieves data from a table specified by the <code>tbl_name<\/code> parameter:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" 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> GetData(\n\t<span class=\"hljs-keyword\">IN<\/span> tbl_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>)\n)\n<span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-keyword\">DECLARE<\/span> unknown_table CONDITION <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-number\">1051<\/span>;\n    \n    <span class=\"hljs-keyword\">DECLARE<\/span> <span class=\"hljs-keyword\">EXIT<\/span> <span class=\"hljs-keyword\">HANDLER<\/span> <span class=\"hljs-keyword\">FOR<\/span> unknown_table \n\t<span class=\"hljs-keyword\">BEGIN<\/span>\n\t\t<span class=\"hljs-keyword\">SHOW<\/span> <span class=\"hljs-keyword\">ERRORS<\/span>;\n    <span class=\"hljs-keyword\">END<\/span>;\n    \n    <span class=\"hljs-keyword\">SET<\/span> @sql_query = <span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-string\">'SELECT * FROM '<\/span>, tbl_name);\n    \n    <span class=\"hljs-keyword\">PREPARE<\/span> stmt <span class=\"hljs-keyword\">FROM<\/span> @sql_query;\n    <span class=\"hljs-keyword\">EXECUTE<\/span> stmt;\n    <span class=\"hljs-keyword\">DEALLOCATE<\/span> <span class=\"hljs-keyword\">PREPARE<\/span> stmt;\n\n<span class=\"hljs-keyword\">END<\/span>$$\n\nDELIMITER ;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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 named condition <code>unknown_table<\/code> that is associated with the MySQL error code <code>1051<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" 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> unknown_table CONDITION <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-number\">1051<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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, declare an exit handler that uses the named condition <code>unknown_table<\/code> and show the errors if the procedure attempts to select from a table that does not exist:<\/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\">DECLARE<\/span> <span class=\"hljs-keyword\">EXIT<\/span> <span class=\"hljs-keyword\">HANDLER<\/span> <span class=\"hljs-keyword\">FOR<\/span> unknown_table \n   <span class=\"hljs-keyword\">BEGIN<\/span>\n      <span class=\"hljs-keyword\">SHOW<\/span> <span class=\"hljs-keyword\">ERRORS<\/span>;\n   <span class=\"hljs-keyword\">END<\/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>Third, construct a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-prepared-statement\/\">prepared statement<\/a> that retrieves all rows and columns from the table specified by the <code>tbl_name<\/code> parameter:<\/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\">SET<\/span> @sql_query = <span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-string\">'SELECT * FROM '<\/span>, tbl_name);\n    \n <span class=\"hljs-keyword\">PREPARE<\/span> stmt <span class=\"hljs-keyword\">FROM<\/span> @sql_query;\n <span class=\"hljs-keyword\">EXECUTE<\/span> stmt;\n <span class=\"hljs-keyword\">DEALLOCATE<\/span> <span class=\"hljs-keyword\">PREPARE<\/span> stmt;<\/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 following example uses the <code>GetData()<\/code> stored procedure to retrieve data from the <code>employees<\/code> table in the <a href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>:<\/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\">CALL<\/span> GetData(<span class=\"hljs-string\">'employees'<\/span>);<\/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>It returns all rows and columns of <code>employees<\/code> table.<\/p>\n\n\n\n<p>However, if we call the stored procedure that retrieves data from the <code>abc<\/code> table that doesn&#8217;t exist, the stored procedure returns an error:<\/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\"><span class=\"hljs-keyword\">CALL<\/span> GetData(<span class=\"hljs-string\">'abc'<\/span>);<\/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>Error:<\/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-comment\">-------+------+-----------------------------------------+<\/span>\n| Level | Code | Message                                 |\n+<span class=\"hljs-comment\">-------+------+-----------------------------------------+<\/span>\n| Error | 1146 | Table 'classicmodels.abc' doesn't exist |\n+<span class=\"hljs-comment\">-------+------+-----------------------------------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.01<\/span> sec)<\/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<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use MySQL <code>DECLARE ... CONDITION<\/code> to associate a name with a condition specified by a MySQL error code or <code>SQLSTATE<\/code> value to make the stored procedure code more readable and expressive.<\/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=\"12672\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/\"\n\t\t\t\tdata-post-title=\"MySQL DECLARE &#8230; CONDITION Statement\"\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=\"12672\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/\"\n\t\t\t\tdata-post-title=\"MySQL DECLARE &#8230; CONDITION Statement\"\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>in this tutorial, you will learn how to use MySQL DECLARE &#8230; CONDITION statement to declare a named error condition.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":518,"menu_order":17,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-12672","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL DECLARE ... CONDITION Statement<\/title>\n<meta name=\"description\" content=\"in this tutorial, you will learn how to use MySQL DECLARE ... CONDITION statement to declare a named error condition.\" \/>\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\/mysql-declare-condition\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL DECLARE ... CONDITION Statement\" \/>\n<meta property=\"og:description\" content=\"in this tutorial, you will learn how to use MySQL DECLARE ... CONDITION statement to declare a named error condition.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-02T14:27:29+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 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\\\/mysql-declare-condition\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-condition\\\/\",\"name\":\"MySQL DECLARE ... CONDITION Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"datePublished\":\"2023-12-02T14:24:26+00:00\",\"dateModified\":\"2023-12-02T14:27:29+00:00\",\"description\":\"in this tutorial, you will learn how to use MySQL DECLARE ... CONDITION statement to declare a named error condition.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-condition\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-condition\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-condition\\\/#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 DECLARE &#8230; CONDITION Statement\"}]},{\"@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 DECLARE ... CONDITION Statement","description":"in this tutorial, you will learn how to use MySQL DECLARE ... CONDITION statement to declare a named error condition.","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\/mysql-declare-condition\/","og_locale":"en_US","og_type":"article","og_title":"MySQL DECLARE ... CONDITION Statement","og_description":"in this tutorial, you will learn how to use MySQL DECLARE ... CONDITION statement to declare a named error condition.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-12-02T14:27:29+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/","url":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/","name":"MySQL DECLARE ... CONDITION Statement","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"datePublished":"2023-12-02T14:24:26+00:00","dateModified":"2023-12-02T14:27:29+00:00","description":"in this tutorial, you will learn how to use MySQL DECLARE ... CONDITION statement to declare a named error condition.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-condition\/#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 DECLARE &#8230; CONDITION Statement"}]},{"@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\/12672","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=12672"}],"version-history":[{"count":5,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/12672\/revisions"}],"predecessor-version":[{"id":12677,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/12672\/revisions\/12677"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/518"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=12672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}