{"id":11031,"date":"2023-10-12T18:42:26","date_gmt":"2023-10-13T01:42:26","guid":{"rendered":"https:\/\/www.mysqltutorial.org\/?page_id=11031"},"modified":"2023-10-12T21:21:58","modified_gmt":"2023-10-13T04:21:58","slug":"mysql-lpad","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/","title":{"rendered":"MySQL LPAD() Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to use the MySQL <code>LPAD()<\/code> function to left-pad a string with a specific set of characters to a specified length.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the MySQL LPAD() function<\/h2>\n\n\n\n<p>The <code>LPAD()<\/code> function allows you to left-pad a string with a specific set of characters to a specified length.<\/p>\n\n\n\n<p>Here&#8217;s the syntax of the <code>LPAD()<\/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\">LPAD(string, length, pad_string)<\/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><code>string<\/code>: The input string that you want to left-pad.<\/li>\n\n\n\n<li><code>length<\/code>: The total length of the resulting string after padding.<\/li>\n\n\n\n<li><code>pad_string<\/code>: The string that you use for padding.<\/li>\n<\/ul>\n\n\n\n<p>If any argument is <code>NULL<\/code>, the <code>LPAD()<\/code> will return <code>NULL<\/code>.<\/p>\n\n\n\n<p>In practice, you use the <code>LPAD()<\/code> function format strings with consistent length, align text in columns or prepare data for display.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL LPAD() function example<\/h2>\n\n\n\n<p>Let&#8217;s take some examples of using the <code>LPAD()<\/code> function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Using LPAD() function to left-pad a numeric string with zeros<\/h3>\n\n\n\n<p>The following example uses the <code>LPAD()<\/code> function to left-pad a numeric string with zero. The result string is always 5 character length:<\/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> \n  <span class=\"hljs-keyword\">LPAD<\/span>(<span class=\"hljs-string\">'123'<\/span>, <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-string\">'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>Output:<\/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-comment\">---------------------+<\/span>\n| LPAD('123', 5, '0') |\n+<span class=\"hljs-comment\">---------------------+<\/span>\n| 00123               |\n+<span class=\"hljs-comment\">---------------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.00<\/span> sec)<\/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>The following example shows how to left-pad numeric strings with zeros:<\/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> \n   <span class=\"hljs-keyword\">LPAD<\/span>(<span class=\"hljs-string\">'123'<\/span>, <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-string\">'0'<\/span>),\n   <span class=\"hljs-keyword\">LPAD<\/span>(<span class=\"hljs-string\">'1234'<\/span>, <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-string\">'0'<\/span>),\n   <span class=\"hljs-keyword\">LPAD<\/span>(<span class=\"hljs-string\">'12345'<\/span>, <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-string\">'0'<\/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>Output:<\/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-comment\">---------------------+----------------------+-----------------------+<\/span>\n| LPAD('123', 5, '0') | LPAD('1234', 5, '0') | LPAD('12345', 5, '0') |\n+<span class=\"hljs-comment\">---------------------+----------------------+-----------------------+<\/span>\n| 00123               | 01234                | 12345                 |\n+<span class=\"hljs-comment\">---------------------+----------------------+-----------------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.00<\/span> sec)<\/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<h3 class=\"wp-block-heading\">2) Using LPAD() function to left-pad a string with spaces<\/h3>\n\n\n\n<p>The following example uses the <code>LPAD()<\/code> function to left-pad a string with two spaces:<\/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> <span class=\"hljs-keyword\">LPAD<\/span>(<span class=\"hljs-string\">'MySQL'<\/span>,<span class=\"hljs-number\">7<\/span>, <span class=\"hljs-string\">' '<\/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>Output:<\/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-comment\">----------------------+<\/span>\n| LPAD('MySQL',7, ' ') |\n+<span class=\"hljs-comment\">----------------------+<\/span>\n|   MySQL              |\n+<span class=\"hljs-comment\">----------------------+<\/span>\n1 row in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.00<\/span> sec)<\/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<h3 class=\"wp-block-heading\">3) Using LPAD() function with table data<\/h3>\n\n\n\n<p>We&#8217;ll use the <code>employees<\/code> table from the <a href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a> for the demonstration:<\/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\/employees.svg\" alt=\"\" class=\"wp-image-10759\"\/><\/figure>\n\n\n\n<p>The following query uses the <code>LPAD()<\/code> function to generate a tree-like structure of employees and their managers within an organization.<\/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\">WITH<\/span> <span class=\"hljs-keyword\">RECURSIVE<\/span> employee_paths <span class=\"hljs-keyword\">AS<\/span>\n  ( <span class=\"hljs-keyword\">SELECT<\/span> employeeNumber,\n           reportsTo managerNumber,\n\t\t   firstName,\n           <span class=\"hljs-number\">1<\/span> lvl\n   <span class=\"hljs-keyword\">FROM<\/span> employees e\n   <span class=\"hljs-keyword\">WHERE<\/span> reportsTo <span class=\"hljs-keyword\">IS<\/span> <span class=\"hljs-literal\">NULL<\/span>\n     <span class=\"hljs-keyword\">UNION<\/span> <span class=\"hljs-keyword\">ALL<\/span>\n     <span class=\"hljs-keyword\">SELECT<\/span> e.employeeNumber,\n            e.reportsTo,\n\t\t\te.firstName,\n            lvl+<span class=\"hljs-number\">1<\/span>\n     <span class=\"hljs-keyword\">FROM<\/span> employees e\n     <span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> employee_paths ep <span class=\"hljs-keyword\">ON<\/span> ep.employeeNumber = e.reportsTo )\n<span class=\"hljs-keyword\">SELECT<\/span> employeeNumber,\n       managerNumber,\n       lvl,\n\t   <span class=\"hljs-keyword\">CONCAT_WS<\/span>(<span class=\"hljs-string\">' '<\/span>,<span class=\"hljs-keyword\">LPAD<\/span>(<span class=\"hljs-string\">''<\/span>,lvl, <span class=\"hljs-string\">'-'<\/span>), firstName) firstName\n<span class=\"hljs-keyword\">FROM<\/span> employee_paths ep\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> lvl, firstName;<\/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>Output:<\/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-comment\">----------------+---------------+------+---------------+<\/span>\n| employeeNumber | managerNumber | lvl  | firstName     |\n+<span class=\"hljs-comment\">----------------+---------------+------+---------------+<\/span>\n|           1002 |          NULL |    1 | - Diane       |\n|           1076 |          1002 |    2 | <span class=\"hljs-comment\">-- Jeff       |<\/span>\n|           1056 |          1002 |    2 | <span class=\"hljs-comment\">-- Mary       |<\/span>\n|           1143 |          1056 |    3 | <span class=\"hljs-comment\">--- Anthony   |<\/span>\n|           1102 |          1056 |    3 | <span class=\"hljs-comment\">--- Gerard    |<\/span>\n|           1621 |          1056 |    3 | <span class=\"hljs-comment\">--- Mami      |<\/span>\n|           1088 |          1056 |    3 | <span class=\"hljs-comment\">--- William   |<\/span>\n|           1611 |          1088 |    4 | <span class=\"hljs-comment\">---- Andy     |<\/span>\n|           1504 |          1102 |    4 | <span class=\"hljs-comment\">---- Barry    |<\/span>\n|           1286 |          1143 |    4 | <span class=\"hljs-comment\">---- Foon Yue |<\/span>\n|           1323 |          1143 |    4 | <span class=\"hljs-comment\">---- George   |<\/span>\n|           1370 |          1102 |    4 | <span class=\"hljs-comment\">---- Gerard   |<\/span>\n|           1188 |          1143 |    4 | <span class=\"hljs-comment\">---- Julie    |<\/span>\n|           1501 |          1102 |    4 | <span class=\"hljs-comment\">---- Larry    |<\/span>\n|           1165 |          1143 |    4 | <span class=\"hljs-comment\">---- Leslie   |<\/span>\n|           1166 |          1143 |    4 | <span class=\"hljs-comment\">---- Leslie   |<\/span>\n|           1337 |          1102 |    4 | <span class=\"hljs-comment\">---- Loui     |<\/span>\n|           1702 |          1102 |    4 | <span class=\"hljs-comment\">---- Martin   |<\/span>\n|           1401 |          1102 |    4 | <span class=\"hljs-comment\">---- Pamela   |<\/span>\n|           1612 |          1088 |    4 | <span class=\"hljs-comment\">---- Peter    |<\/span>\n|           1216 |          1143 |    4 | <span class=\"hljs-comment\">---- Steve    |<\/span>\n|           1619 |          1088 |    4 | <span class=\"hljs-comment\">---- Tom      |<\/span>\n|           1625 |          1621 |    4 | <span class=\"hljs-comment\">---- Yoshimi  |<\/span>\n+<span class=\"hljs-comment\">----------------+---------------+------+---------------+<\/span>\n23 rows in <span class=\"hljs-keyword\">set<\/span> (<span class=\"hljs-number\">0.00<\/span> sec)<\/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>In this example, we use the <code>LPAD()<\/code> function to left-pad the character <code>-<\/code> based on the level of the employee in the reporting structure. <\/p>\n\n\n\n<p>Here&#8217;s how it works.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>WITH RECURSIVE employee_paths AS<\/code>: This clause starts the definition of a common table expression (CTE) named <code>employee_paths<\/code>. The <code>RECURSIVE<\/code> keyword indicates that this CTE will be used recursively.<\/li>\n\n\n\n<li><code>( SELECT employeeNumber, reportsTo managerNumber, firstName, 1 lvl FROM employees e WHERE reportsTo IS NULL<\/code>: This is the initial (or base) part of the CTE. It selects employees whose <code>reportsTo<\/code> field is <code>NULL<\/code>, which represents the top-level management or employees who have no managers. It assigns a level (<code>lvl<\/code>) of 1 to these top-level employees.<\/li>\n\n\n\n<li><code>UNION ALL<\/code>: This is used to combine the results of the initial and subsequent recursive parts of the CTE.<\/li>\n\n\n\n<li><code>SELECT e.employeeNumber, e.reportsTo, e.firstName, lvl+1 FROM employees e INNER JOIN employee_paths ep ON ep.employeeNumber = e.reportsTo<\/code>: This is the recursive part of the CTE. It selects employees (<code>e<\/code>) and their attributes (employee number, manager&#8217;s number, first name) where the employee&#8217;s manager number (<code>reportsTo<\/code>) matches the <code>employeeNumber<\/code> of the records in the CTE (<code>employee_paths<\/code>). It also increments the level (<code>lvl<\/code>) by 1 for each iteration.<\/li>\n\n\n\n<li>The <code>SELECT<\/code> statement following the CTE is used to retrieve the final results from the CTE.<\/li>\n\n\n\n<li><code>SELECT employeeNumber, managerNumber, lvl, CONCAT_WS(' ',LPAD('',lvl, '-'), firstName) firstName FROM employee_paths ep<\/code>: This part of the query retrieves the following columns:\n<ul class=\"wp-block-list\">\n<li><code>employeeNumber<\/code>: The employee&#8217;s unique identifier.<\/li>\n\n\n\n<li><code>managerNumber<\/code>: The unique identifier of the employee&#8217;s manager.<\/li>\n\n\n\n<li><code>lvl<\/code>: The level or depth of the employee within the organization hierarchy.<\/li>\n\n\n\n<li><code>CONCAT_WS(' ',LPAD('',lvl, '-'), firstName) firstName<\/code>: It concatenates the following values:\n<ul class=\"wp-block-list\">\n<li><code>LPAD('',lvl, '-')<\/code>: It left-pads an empty string with hyphens (based on the <code>lvl<\/code> value) to create an indentation that represents the employee&#8217;s position in the hierarchy.<\/li>\n\n\n\n<li><code>firstName<\/code>: The first name of the employee.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>ORDER BY lvl, firstName<\/code>: The final result set is ordered first by the level (<code>lvl<\/code>) to maintain the hierarchy order, and then by the first name (<code>firstName<\/code>) within each level.<\/li>\n<\/ol>\n\n\n\n<p>For detailed information on the recursive CTE, please check out the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-recursive-cte\/\">MySQL Recursive CTE tutorial<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the MySQL <code>LPAD()<\/code> function to left-pad a string with a specific set of characters to a specified length.<\/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=\"11031\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/\"\n\t\t\t\tdata-post-title=\"MySQL LPAD() 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=\"11031\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/\"\n\t\t\t\tdata-post-title=\"MySQL LPAD() 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>You will learn how to use the MySQL LPAD() function to left-pad a string with a specific set of characters to a specified length.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":7027,"menu_order":14,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-11031","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 LPAD<\/title>\n<meta name=\"description\" content=\"You will learn how to use the MySQL LPAD() function to left-pad a string with a specific set of characters to a specified length.\" \/>\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-string-functions\/mysql-lpad\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL LPAD\" \/>\n<meta property=\"og:description\" content=\"You will learn how to use the MySQL LPAD() function to left-pad a string with a specific set of characters to a specified length.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-13T04:21:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2023\/10\/employees.svg\" \/>\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-string-functions\\\/mysql-lpad\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/mysql-lpad\\\/\",\"name\":\"MySQL LPAD\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/mysql-lpad\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/mysql-lpad\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/employees.svg\",\"datePublished\":\"2023-10-13T01:42:26+00:00\",\"dateModified\":\"2023-10-13T04:21:58+00:00\",\"description\":\"You will learn how to use the MySQL LPAD() function to left-pad a string with a specific set of characters to a specified length.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/mysql-lpad\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/mysql-lpad\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/mysql-lpad\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/employees.svg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/employees.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-string-functions\\\/mysql-lpad\\\/#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 LPAD() 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 LPAD","description":"You will learn how to use the MySQL LPAD() function to left-pad a string with a specific set of characters to a specified length.","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-string-functions\/mysql-lpad\/","og_locale":"en_US","og_type":"article","og_title":"MySQL LPAD","og_description":"You will learn how to use the MySQL LPAD() function to left-pad a string with a specific set of characters to a specified length.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-10-13T04:21:58+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2023\/10\/employees.svg","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/","url":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/","name":"MySQL LPAD","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2023\/10\/employees.svg","datePublished":"2023-10-13T01:42:26+00:00","dateModified":"2023-10-13T04:21:58+00:00","description":"You will learn how to use the MySQL LPAD() function to left-pad a string with a specific set of characters to a specified length.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2023\/10\/employees.svg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2023\/10\/employees.svg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-string-functions\/mysql-lpad\/#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 LPAD() 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\/11031","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=11031"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/11031\/revisions"}],"predecessor-version":[{"id":11062,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/11031\/revisions\/11062"}],"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=11031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}