What MySQL returns, if the length of the original string is greater than the length specified as an argument in LPAD() or RPAD() functions?

MySQLMySQLi Database

<p>In this case, MySQL will not pad anything and truncate the characters from the original string up to the value of length provided as the argument in LPAD() or RPAD() functions.</p><h4>Example</h4><pre class="result notranslate">mysql&gt; Select LPAD(&#39;ABCD&#39;,3,&#39;*&#39;); +--------------------+ | LPAD(&#39;ABCD&#39;,3,&#39;*&#39;) | +--------------------+ | ABC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| +--------------------+ 1 row in set (0.00 sec) mysql&gt; Select RPAD(&#39;ABCD&#39;,3,&#39;*&#39;); +--------------------+ | RPAD(&#39;ABCD&#39;,3,&#39;*&#39;) | +--------------------+ | ABC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| +--------------------+ 1 row in set (0.00 sec)</pre><p>We can observe from the above example that both the functions do not pad &lsquo;*&rsquo; and truncate the original string up to the length specified i.e. 3 as the argument.</p>
raja
Updated on 07-Feb-2020 10:10:28

Advertisements