{"id":4702,"date":"2013-12-17T19:25:39","date_gmt":"2013-12-18T03:25:39","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=4702"},"modified":"2023-10-12T21:58:34","modified_gmt":"2023-10-13T04:58:34","slug":"mysql-instr","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-instr\/","title":{"rendered":"MySQL INSTR() Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: This tutorial shows you how to use the MySQL <code>INSTR()<\/code> function to return the position of the first occurrence of a string.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the MySQL INSTR() function<\/h2>\n\n\n\n<p>Sometimes, you want to locate a substring in a string or to check if a substring exists in a string. In this case, you can use a string built-in function called <code>INSTR<\/code>.<\/p>\n\n\n\n<p>The <code>INSTR<\/code> function returns the position of the first occurrence of a substring in a string. If the substring is not found in the str, the <code>INSTR<\/code> function returns zero (0).<\/p>\n\n\n\n<p>The following illustrates the syntax of the <code>INSTR<\/code> function.<\/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\">INSTR(str,substr);<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#1\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>The <code>INSTR<\/code> function accepts two arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>str<\/code> is the string that you want to search in.<\/li>\n\n\n\n<li>The <code>substr<\/code> is the substring that you want to search for.<\/li>\n<\/ul>\n\n\n\n<p>The <code>INSTR<\/code> function is not case-sensitive. It means that it does not matter if you pass the lowercase, uppercase, title case, etc., the results are always the same.<\/p>\n\n\n\n<p>If you want the <code>INSTR<\/code> function to perform searches in a case-sensitive manner on a non-binary string, you use the <code>BINARY<\/code> operator to cast a one the argument of the <code>INSTR<\/code> function from a non-binary string to a binary string.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The MySQL INSTR() function examples<\/h2>\n\n\n\n<p>The following statement returns the position of the substring MySQL in the <code>MySQL INSTR<\/code> string.<\/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\">SELECT<\/span> <span class=\"hljs-keyword\">INSTR<\/span>(<span class=\"hljs-string\">'MySQL INSTR'<\/span>, <span class=\"hljs-string\">'MySQL'<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#2\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"201\" height=\"72\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example.jpg\" alt=\"MySQL INSTR example\" class=\"wp-image-4751\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example.jpg 201w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example-200x72.jpg 200w\" sizes=\"auto, (max-width: 201px) 100vw, 201px\" \/><\/figure>\n\n\n\n<p>The following statement returns the same result because the <code>INSTR<\/code> function is case-insensitive.<\/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\">SELECT<\/span> <span class=\"hljs-keyword\">INSTR<\/span>(<span class=\"hljs-string\">'MySQL INSTR'<\/span>, <span class=\"hljs-string\">'mysql'<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#3\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>To force <code>INSTR<\/code> function to search based on case-sensitive fashion, you use the <code>BINARY<\/code> operator as follows:<\/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\">SELECT<\/span> <span class=\"hljs-keyword\">INSTR<\/span>(<span class=\"hljs-string\">'MySQL INSTR'<\/span>, <span class=\"hljs-built_in\">BINARY<\/span> <span class=\"hljs-string\">'mysql'<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#4\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"230\" height=\"83\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-case-sensitive-example.jpg\" alt=\"MySQL INSTR case-sensitive example\" class=\"wp-image-4745\" title=\"MySQL INSTR case-sensitive example\"\/><\/figure>\n\n\n\n<p>The result is different because mysql vs. MySQL now with the <code>BINARY<\/code> operator.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The INSTR function vs. LIKE operator<\/h2>\n\n\n\n<p>We will use the <code>products<\/code> table in the <a href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2023\/10\/products.svg\" alt=\"\" class=\"wp-image-10788\"\/><\/figure>\n\n\n\n<p>Suppose you want to find a product whose name contains the <code>car<\/code> keyword, you can use the <code>INSTR<\/code> function as follows:<\/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> \n    productName\n<span class=\"hljs-keyword\">FROM<\/span>\n    products\n<span class=\"hljs-keyword\">WHERE<\/span>\n    <span class=\"hljs-keyword\">INSTR<\/span>(productname,<span class=\"hljs-string\">'Car'<\/span>) &gt; <span class=\"hljs-number\">0<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#5\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"229\" height=\"153\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-in-WHERE-clause.jpg\" alt=\"MySQL INSTR in WHERE clause\" class=\"wp-image-4747\" title=\"MySQL INSTR in WHERE clause\"\/><\/figure>\n\n\n\n<p>Besides the <code>INSTR<\/code> function, you can use the <code>LIKE<\/code> operator to match the <code>Car<\/code> pattern.<\/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\">SELECT<\/span> \n    productname\n<span class=\"hljs-keyword\">FROM<\/span>\n    products\n<span class=\"hljs-keyword\">WHERE<\/span>\n    productname <span class=\"hljs-keyword\">LIKE<\/span> <span class=\"hljs-string\">'%Car%'<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#6\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>Both queries return the same result. So which one is faster, the <code>INSTR<\/code> or the <code>LIKE<\/code> operator?<\/p>\n\n\n\n<p>The answer is that they are the same. They are both case-sensitive and perform full table scans.<\/p>\n\n\n\n<p>Let&#8217;s create an index on the <code>productname<\/code> column.<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">INDEX<\/span> idx_products_name <span class=\"hljs-keyword\">ON<\/span> products(productname);<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#7\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<p>If you use the <code>LIKE<\/code> operator with the prefix search, on this indexed column, the <code>LIKE<\/code> operator will perform faster than the <code>INSTR<\/code> function.<\/p>\n\n\n\n<p>See the following statement.<\/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\">SELECT<\/span> \n    productname\n<span class=\"hljs-keyword\">FROM<\/span>\n    products\n<span class=\"hljs-keyword\">WHERE<\/span>\n    productname <span class=\"hljs-keyword\">LIKE<\/span> <span class=\"hljs-string\">'1900%'<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#8\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"156\" height=\"64\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-vs-LIKE.jpg\" alt=\"MySQL INSTR vs LIKE\" class=\"wp-image-4749\" title=\"MySQL INSTR vs LIKE\"\/><\/figure>\n\n\n\n<p>You can check it using the <code>EXPLAIN<\/code> statement:<\/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\">EXPLAIN<\/span> <span class=\"hljs-keyword\">SELECT<\/span> \n    productname\n<span class=\"hljs-keyword\">FROM<\/span>\n    products\n<span class=\"hljs-keyword\">WHERE<\/span>\n    productname <span class=\"hljs-keyword\">LIKE<\/span> <span class=\"hljs-string\">'1900%'<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#9\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"738\" height=\"45\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-LIKE-with-INDEX.jpg\" alt=\"MySQL INSTR LIKE with INDEX\" class=\"wp-image-4748\" title=\"MySQL INSTR LIKE with INDEX\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-LIKE-with-INDEX.jpg 738w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-LIKE-with-INDEX-300x18.jpg 300w\" sizes=\"auto, (max-width: 738px) 100vw, 738px\" \/><\/figure>\n\n\n\n<p>And compare with the following statement that uses the <code>INSTR<\/code> function.<\/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\">EXPLAIN<\/span> <span class=\"hljs-keyword\">SELECT<\/span> \n    productname\n<span class=\"hljs-keyword\">FROM<\/span>\n    products\n<span class=\"hljs-keyword\">WHERE<\/span>\n    <span class=\"hljs-keyword\">instr<\/span>(productname,<span class=\"hljs-string\">'1900'<\/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><a class=\"sql\" href=\"https:\/\/www.mysqltutorial.org\/tryit\/query\/mysql-instr\/#10\" target=\"_blank\" rel=\"noopener noreferrer\">Try It Out<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"44\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-with-INDEX.jpg\" alt=\"MySQL INSTR with INDEX\" class=\"wp-image-4752\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-with-INDEX.jpg 705w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-with-INDEX-300x19.jpg 300w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<p>The <code>INSTR<\/code> function performs a table scan even though the <code>productname<\/code> column has an index. This is because MySQL cannot make any assumption about the semantics of the <code>INSTR<\/code> function, whereby MySQL can utilize its understanding of the semantics of the <code>LIKE<\/code> operator.<\/p>\n\n\n\n<p>The fastest way to test if a substring exists in a string is to use a<a href=\"https:\/\/www.mysqltutorial.org\/mysql-full-text-search\/\"> full-text index<\/a>. However, it requires configuring and maintaining the index properly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ue the <code>INSTR<\/code> function to find the position of the first occurrence of a substring in a string.<\/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=\"4702\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-instr\/\"\n\t\t\t\tdata-post-title=\"MySQL INSTR() Function\"\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=\"4702\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-instr\/\"\n\t\t\t\tdata-post-title=\"MySQL INSTR() Function\"\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 the MySQL INSTR function to return the position of the first occurrence of a string.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":7027,"menu_order":20,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4702","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 INSTR Function<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to use the MySQL INSTR function to return the position of the first occurrence of a substring.\" \/>\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-instr\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL INSTR Function\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to use the MySQL INSTR function to return the position of the first occurrence of a substring.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-instr\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-13T04:58:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/\",\"name\":\"MySQL INSTR Function\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2013\\\/12\\\/MySQL-INSTR-example.jpg\",\"datePublished\":\"2013-12-18T03:25:39+00:00\",\"dateModified\":\"2023-10-13T04:58:34+00:00\",\"description\":\"This tutorial shows you how to use the MySQL INSTR function to return the position of the first occurrence of a substring.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2013\\\/12\\\/MySQL-INSTR-example.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2013\\\/12\\\/MySQL-INSTR-example.jpg\",\"width\":201,\"height\":72},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-instr\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL String Functions\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL INSTR() Function\"}]},{\"@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 INSTR Function","description":"This tutorial shows you how to use the MySQL INSTR function to return the position of the first occurrence of a substring.","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-instr\/","og_locale":"en_US","og_type":"article","og_title":"MySQL INSTR Function","og_description":"This tutorial shows you how to use the MySQL INSTR function to return the position of the first occurrence of a substring.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-instr\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-10-13T04:58:34+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example.jpg","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-instr\/","url":"https:\/\/www.mysqltutorial.org\/mysql-instr\/","name":"MySQL INSTR Function","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-instr\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-instr\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example.jpg","datePublished":"2013-12-18T03:25:39+00:00","dateModified":"2023-10-13T04:58:34+00:00","description":"This tutorial shows you how to use the MySQL INSTR function to return the position of the first occurrence of a substring.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-instr\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-instr\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-instr\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example.jpg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2013\/12\/MySQL-INSTR-example.jpg","width":201,"height":72},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-instr\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL String Functions","item":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/"},{"@type":"ListItem","position":3,"name":"MySQL INSTR() Function"}]},{"@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\/4702","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=4702"}],"version-history":[{"count":3,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/4702\/revisions"}],"predecessor-version":[{"id":11083,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/4702\/revisions\/11083"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/7027"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=4702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}