Padding a string to a specified length by prepending (LPAD) or appending (RPAD) a fill character.
Pads a string to a specified length by prepending (LPAD) or appending (RPAD) a fill character. Useful for zero-padding numbers and formatting fixed-width output.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 5.0 | LPAD and RPAD are both built-in. If the string is longer than the target length, the result is silently truncated to that length. |
| PostgreSQL | ✓ Supported | 7.4 | LPAD and RPAD are built-in. The fill string defaults to a space if omitted. If the input is longer than length, the result is truncated from the right. |
| SQL Server | ✗ Not Supported | — | No native LPAD or RPAD. Standard workarounds use RIGHT/LEFT with REPLICATE. |
| Oracle | ✓ Supported | 7 | LPAD and RPAD are standard Oracle string functions, available in SQL and PL/SQL. |
| SQLite | ✗ Not Supported | — | No native LPAD or RPAD. Use printf() / format() for left-zero-padding integers. General string padding requires application-side logic or a custom UDF. |
LPAD and RPAD are available in MySQL, PostgreSQL, and Oracle but absent in SQL Server and SQLite. SQL Server's REPLICATE-based pattern is verbose but reliable and worth encapsulating in a scalar function if used frequently. SQLite's printf('%0Nd', value) handles numeric zero-padding cleanly but there is no general-purpose string-padding path without a custom UDF. A subtle shared behavior in MySQL and PostgreSQL: if the source string is already longer than the target length, it is silently truncated to that length — data loss that can go unnoticed if the target length is set too small.
LPAD and RPAD are both built-in. If the string is longer than the target length, the result is silently truncated to that length.
LPAD and RPAD are built-in. The fill string defaults to a space if omitted. If the input is longer than length, the result is truncated from the right.
No native LPAD or RPAD. Standard workarounds use RIGHT/LEFT with REPLICATE.
LPAD and RPAD are standard Oracle string functions, available in SQL and PL/SQL.
No native LPAD or RPAD. Use printf() / format() for left-zero-padding integers. General string padding requires application-side logic or a custom UDF.