Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Tuesday, 20 February 2024

RPAD in TERADATA

In Teradata, there isn't a built-in RPAD function like in some other SQL databases such as Oracle or MySQL. However, you can achieve the same functionality using string concatenation and the REPEAT function. Here's an example of how to pad a string to the right in Teradata:


SELECT employee_name || REPEAT('*', 15 - CHAR_LENGTH(employee_name)) AS padded_name

FROM employees;


In this query:

- || is the string concatenation operator in Teradata.

- REPEAT('*', 15 - CHAR_LENGTH(employee_name)) generates a string of asterisks (*) repeated enough times to fill the remaining characters needed to reach a total length of 15 characters, subtracting the length of the original employee_name.

- CHAR_LENGTH(employee_name) calculates the length of the original employee_name.

- employee_name || REPEAT('*', 15 - CHAR_LENGTH(employee_name)) concatenates the original employee_name with the generated padding string.


This query will pad each employee_name with asterisks (*) to make them 15 characters long, similar to the RPAD function in other databases.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.