{"id":12682,"date":"2023-12-03T18:19:25","date_gmt":"2023-12-04T01:19:25","guid":{"rendered":"https:\/\/www.mysqltutorial.org\/?page_id=12682"},"modified":"2023-12-05T17:14:37","modified_gmt":"2023-12-06T00:14:37","slug":"mysql-declare-handler","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/","title":{"rendered":"MySQL DECLARE &#8230; HANDLER Statement"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use MySQL handler to handle errors or warnings encountered in stored procedures.<\/p>\n\n\n\n<p>In MySQL, conditions refer to errors, warnings, or exceptional cases that require proper handling. <\/p>\n\n\n\n<p>When a condition arises during the execution of a stored procedure, you should handle it properly, such as exiting or continuing the current code block.<\/p>\n\n\n\n<p>To handle a condition, you declare a <em>handler<\/em> using the <code>DECLARE ... HANDLER<\/code> statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL DECLARE &#8230; HANDLER statement<\/h2>\n\n\n\n<p>Here is the basic syntax of the <code>DECLARE...HANDLER<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">DECLARE<\/span> { <span class=\"hljs-keyword\">EXIT<\/span> | <span class=\"hljs-keyword\">CONTINUE<\/span> } HANDLER\n    <span class=\"hljs-keyword\">FOR<\/span> condition_value &#91;, condition_value] ...\n    statement<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><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>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>DECLARE { EXIT | CONTINUE } HANDLER<\/code>: This declares a handler, instructing whether it should <em>exit<\/em> or <em>continue<\/em> the enclosing stored procedure when a specified condition occurs.\n<ul class=\"wp-block-list\">\n<li><code>EXIT<\/code>: The stored procedure will terminate.<\/li>\n\n\n\n<li><code>CONTINUE<\/code>: The stored procedure will continue execution.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>FOR condition_value [, condition_value] ...<\/code>:  This specifies the conditions that activate the handler, and you can specify multiple conditions by separating them with commas.<\/li>\n\n\n\n<li><code>statement<\/code>: This statement or block of statements executes when the stored procedure encounters one of the specified conditions.<\/li>\n<\/ul>\n\n\n\n<p>The <code>condition_value<\/code> can be one of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>mysql_error_code<\/code> &#8211; This is an integer indicating a MySQL error code such as <code>1051<\/code>.<\/li>\n\n\n\n<li><code>SQLWARNING<\/code> &#8211; This is a shorthand for the class of <code>SQLSTATE<\/code> values that begin with<code> '01'<\/code>.<\/li>\n\n\n\n<li><code>NOT FOUND<\/code> &#8211; This is a shorthand for the class of <code>SQLSTATE<\/code> values that begin with <code>'02'<\/code>.<\/li>\n\n\n\n<li><code>SQLEXCEPTION<\/code> &#8211; This is a shorthand for the class of <code>SQLSTATE<\/code> values that do not begin with <code>'00'<\/code>, <code>'01'<\/code>, or <code>'02'<\/code>.<\/li>\n\n\n\n<li><code>SQLSTATE [VALUE] sqlstate_value<\/code> &#8211; This is a string that indicates an <code>SQLSTATE<\/code> value, such as <code>'42S01'<\/code> means &#8220;Unknown table&#8221;.<\/li>\n<\/ul>\n\n\n\n<p><code>SQLSTATE<\/code> is a five-character that provides information about the result of an SQL operation. An <code>SQLSTATE<\/code> consists of two parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Class Code (First two characters):<\/strong> Indicates the general category of the error.<\/li>\n\n\n\n<li><strong>Subclass Code (Next three characters):<\/strong> Provides more specific information about the error within the general category.<\/li>\n<\/ul>\n\n\n\n<p>For example, a SQLSTATE code of &#8217;42S02&#8242; indicates a missing table, where &#8217;42&#8217; is the class code for syntax error or access rule violation, and &#8216;S02&#8217; is the subclass code indicating that the table is not found.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL DECLARE &#8230; HANDLER example<\/h2>\n\n\n\n<p>First, create a table called <code>users<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> <span class=\"hljs-keyword\">users<\/span> (\n    user_id <span class=\"hljs-built_in\">INT<\/span> AUTO_INCREMENT PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n    username <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">UNIQUE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n    email <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\n);<\/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>Second, define a stored procedure that inserts a new user into the <code>users<\/code> table:<\/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\">DELIMITER \/\/\n\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">PROCEDURE<\/span> insert_user(\n\t<span class=\"hljs-keyword\">IN<\/span> p_username <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>), \n    <span class=\"hljs-keyword\">IN<\/span> p_email <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">50<\/span>)\n)\n<span class=\"hljs-keyword\">BEGIN<\/span>\n  <span class=\"hljs-comment\">-- SQLSTATE for unique constraint violation<\/span>\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> <span class=\"hljs-keyword\">SQLSTATE<\/span> <span class=\"hljs-string\">'23000'<\/span>\n  <span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-comment\">-- Handler actions when a duplicate username is detected<\/span>\n    <span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-string\">'Error: Duplicate username. Please choose a different username.'<\/span> <span class=\"hljs-keyword\">AS<\/span> Message;\n  <span class=\"hljs-keyword\">END<\/span>;\n\n  <span class=\"hljs-comment\">-- Attempt to insert the user into the table<\/span>\n  <span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> <span class=\"hljs-keyword\">users<\/span> (username, email) <span class=\"hljs-keyword\">VALUES<\/span> (p_username, p_email);\n\n  <span class=\"hljs-comment\">-- If the insertion was successful, display a success message<\/span>\n  <span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-string\">'User inserted successfully'<\/span> <span class=\"hljs-keyword\">AS<\/span> Message;\n\n<span class=\"hljs-keyword\">END<\/span> \/\/\n\nDELIMITER ;<\/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>How it works.<\/p>\n\n\n\n<p>The <code>insert_user()<\/code> stored procedure accepts two parameters username and email.<\/p>\n\n\n\n<p>In the stored procedure, declare an exit handler that is activated when a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-unique-constraint\/\">unique constraint<\/a> violation occurs, which is indicated by the SQLSTATE &#8216;23000&#8217;:<\/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\"><span class=\"hljs-keyword\">DECLARE<\/span> <span class=\"hljs-keyword\">EXIT<\/span> <span class=\"hljs-keyword\">HANDLER<\/span> <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-keyword\">SQLSTATE<\/span> <span class=\"hljs-string\">'23000'<\/span><\/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>When the error occurs, the stored procedure returns the following message and terminates the execution immediately:<\/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\">SELECT<\/span> <span class=\"hljs-string\">'Error: Duplicate username. Please choose a different username.'<\/span> <span class=\"hljs-keyword\">AS<\/span> Message;<\/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>Insert a new row into the <code>users<\/code> table, if a unique constraint violation occurs, the code within the <code>BEGIN ... END<\/code> block of the handler will execute:<\/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\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> <span class=\"hljs-keyword\">users<\/span> (username, email) <span class=\"hljs-keyword\">VALUES<\/span> (p_username, p_email);<\/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>If the insert succeeds, the following line of code will execute:<\/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\">SELECT<\/span> <span class=\"hljs-string\">'User inserted successfully'<\/span> <span class=\"hljs-keyword\">AS<\/span> Message;<\/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>Third, insert a new row into the <code>users<\/code> table by calling the <code>insert_user<\/code> stored procedure:<\/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> insert_user(<span class=\"hljs-string\">'jane'<\/span>,<span class=\"hljs-string\">'jane@example.com'<\/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 the following message:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+----------------------------+\n| Message                    |\n+----------------------------+\n| User inserted successfully |\n+----------------------------+\n1 row in set (0.01 sec)\n\nQuery OK, 0 rows affected (0.01 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you execute the statement again, it&#8217;ll return the following error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+----------------------------------------------------------------+\n| Message                                                        |\n+----------------------------------------------------------------+\n| Error: Duplicate username. Please choose a different username. |\n+----------------------------------------------------------------+\n1 row in set (0.00 sec)\n\nQuery OK, 0 rows affected (0.01 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/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 handlers to handle conditions including warnings and errors in stored procedures.<\/li>\n\n\n\n<li>Use the <code>DECLARE...HANDLER<\/code> statement to declare a handler.<\/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=\"12682\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/\"\n\t\t\t\tdata-post-title=\"MySQL DECLARE &#8230; HANDLER 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=\"12682\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/\"\n\t\t\t\tdata-post-title=\"MySQL DECLARE &#8230; HANDLER 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>This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":518,"menu_order":16,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-12682","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 ... HANDLER Statement<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.\" \/>\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-handler\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL DECLARE ... HANDLER Statement\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-06T00:14:37+00:00\" \/>\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\\\/mysql-declare-handler\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-handler\\\/\",\"name\":\"MySQL DECLARE ... HANDLER Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"datePublished\":\"2023-12-04T01:19:25+00:00\",\"dateModified\":\"2023-12-06T00:14:37+00:00\",\"description\":\"This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-handler\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-handler\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-stored-procedure\\\/mysql-declare-handler\\\/#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; HANDLER 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 ... HANDLER Statement","description":"This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.","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-handler\/","og_locale":"en_US","og_type":"article","og_title":"MySQL DECLARE ... HANDLER Statement","og_description":"This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-12-06T00:14:37+00:00","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/","url":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/","name":"MySQL DECLARE ... HANDLER Statement","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"datePublished":"2023-12-04T01:19:25+00:00","dateModified":"2023-12-06T00:14:37+00:00","description":"This tutorial shows you how to use MySQL handler to handle exceptions or errors encountered in stored procedures.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/mysql-declare-handler\/#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; HANDLER 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\/12682","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=12682"}],"version-history":[{"count":3,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/12682\/revisions"}],"predecessor-version":[{"id":12686,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/12682\/revisions\/12686"}],"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=12682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}