REPEAT scalar function
The REPEAT function returns a character string that is composed of an argument that is repeated a specified number of times.
The schema is SYSIBM.
- expression
- An expression that specifies the string to be repeated.
The expression must return a value that is a built-in character string,
graphic string, or binary string data type that is not a LOB.
The argument can also be a numeric data type. The numeric argument is implicitly cast to a VARCHAR data type.
The actual length of the string must be greater or equal to 1 and less than or equal to 32704 bytes. - integer
- integer must be a positive large integer
value that specifies the number of times to repeat the string.
The argument can also be a character string or graphic string data type. The string input is implicitly cast to a numeric value of DECFLOAT(34) which is then assigned to an INTEGER value.
The result can be null; if any argument is null, the result is the null value.
The encoding scheme of the result is the same as expression. The data type of the result of the function depends on the data type of expression:
- VARBINARY if expression is a binary string
- VARCHAR if expression is a character string
- VARGRAPHIC if expression is graphic string
The CCSID of the result is the same as the CCSID of expression.
If integer is a constant, the length attribute of the result is the length attribute of expression times integer. Otherwise, the length attribute depends on the data type of the result:
- 4000 for VARBINARY and VARCHAR
- 2000 for VARGRAPHIC
The actual length of the result is the actual length of expression times integer. If the actual length of the result string exceeds the maximum for the return type, an error occurs.
SELECT REPEAT('abc',2)
FROM SYSIBM.SYSDUMMY1;
SELECT CHAR(REPEAT('REPEAT THIS',5), 60)
FROM SYSIBM.SYSDUMMY1;
This example results in 'REPEAT
THISREPEAT THISREPEAT THISREPEAT THISREPEAT THIS '. SELECT LENGTH(REPEAT('REPEAT THIS',0))
FROM SYSIBM.SYSDUMMY1;
SELECT LENGTH(REPEAT('', 5))
FROM SYSIBM.SYSDUMMY1;