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.