0

I have a requirement to query with following input and results.

MariaDB [db]> select LPAD('COMP1', 8, 'X');
+-----------------------+
| LPAD('COMP1', 8, 'X') |
+-----------------------+
| XXXCOMP1              |
+-----------------------+

In the above example you can see, the input "COMP1" has the length 5, due to which LPAD has prefixed with 3 additional PADDED string. Now if the length of an input is higher than the limit 8. it has to result as is, without trimming the content.

MariaDB [db]> select LPAD('COMP1', 8, 'X');
+-----------------------+
| LPAD('COMP10199', 8, 'X') |
+-----------------------+
| COMP1019              |
+-----------------------+

It got trimmed here, where as the expected value in my requirement is COMP10199, I do not wish to use IF condition here to check the length. I'm looking for an alternative to LPAD, where the higher length values should not be trimmed. or a user-defined aggregate function.

ameenulla0007
  • 2,663
  • 1
  • 12
  • 15
  • Does this answer your question? [LPAD without trimming in mysql](https://stackoverflow.com/questions/54909026/lpad-without-trimming-in-mysql) – P.Salmon Mar 31 '20 at 09:53
  • ZEROFILL is not my requirement, i have different character to be prefixed. so zerofill will not help to solve it. – ameenulla0007 Apr 01 '20 at 07:41

0 Answers0