What, no REPEAT(X,n) function for Teradata?

Analytics

What, no REPEAT(X,n) function for Teradata?

Hello,

I wants to log some simple ascii bar charts.

e.g.
5 *****
6 ******
9 *********
3 ***
2 **
1 *

every other db has either a REPEAT, REPLICATE, RPAD funtion to get the job done.

any suggestions for TD?
5 REPLIES

Re: What, no REPEAT(X,n) function for Teradata?

doh, substr('******************************',1,datacol) works!

Re: What, no REPEAT(X,n) function for Teradata?

what does 'datacol' in the 3rd parameter mean? Can you pls explain

Re: What, no REPEAT(X,n) function for Teradata?

That's equivalent to the "n" parameter in your REPEAT function.  The number of times you intend to repeat the character.  mcrad pegged this one...

Re: What, no REPEAT(X,n) function for Teradata?

Here's my solution:

The Account number is held as a INTEGER and we want to left pad with zeros to make it an 8-character field fopr display purposes. So,

SELECT

 CAST(00123456 AS INTEGER) AS Acc_No,

 SUBSTRING('00000000' FROM 1 FOR 8 - CHARACTER_LENGTH(TRIM(Acc_No))) || TRIM(Acc_No)

;

N/A

Re: What, no REPEAT(X,n) function for Teradata?

Since TD14 there's LPAD/RPAD or TO_CHAR:

LPAD(TRIM(ACC_No), 8, '0')
TO_CHAR(Acc_no, '00000000')

Before you can apply a FORMAT:

CAST(CAST(Acc_no AS FORMAT '9(8)') AS CHAR(8))