RPAD
The RPAD
function returns Expression1
, right-padded to length n
characters with Expression2
, replicated as many times as necessary. This function is useful for formatting the output of a query.
SQL syntax
RPAD (Expression1, n [,Expression2])
Parameters
RPAD
has the parameters:
Parameter | Description |
---|---|
|
|
|
Length of characters returned by |
|
|
Description
-
If
Expression1
is of typeCHAR
orVARCHAR2
, the data type returned isVARCHAR2
. IfExpression1
is of typeNCHAR
orNVARCHAR2
, the data type returned isNVARCHAR2
. IfExpression1
is a LOB, the data type returned is the same as the LOB data type provided. -
The returned data type length is equal to
n
ifn
is a constant. Otherwise, the maximum result length of 8300 is returned. -
You can specify
TT_CHAR
,TT_VARCHAR
,TT_NCHAR
, andTT_NVARCHAR
forExpression1
andExpression2
. IfExpression1
is of typeTT_CHAR
orTT_VARCHAR
, the data type returned isTT_VARCHAR
. IfExpression1
is of typeTT_NCHAR
orTT_NVARCHAR
, the data type returned isTT_NVARCHAR
. -
For
CHAR
,VARCHAR2
,NCHAR
,NVARCHAR2
,CLOB
orNCLOB
data types:-
If either
Expression1
orExpression2
isNULL
, the result isNULL
. Ifn
is less than or equal to0
, the result isNULL
.
-
-
For
TT_CHAR
,TT_VARCHAR
,TT_NCHAR
andTT_NVARCHAR
types:-
If either
Expression1
orExpression2
is notNULL
and ifn
is less than or equal to0
, the result is the empty string.
-
Examples
Concatenate first_name
and last_name
from the employees
table. Call the RPAD
function to return first_name
right-padded to length 12 with spaces and call RPAD
a second time to return last_name
right-padded to length 12 with spaces. Select first five rows.
Command> SELECT FIRST 5 CONCAT (RPAD (first_name,12), RPAD (last_name,12)) FROM employees ORDER BY first_name, last_name; < Adam Fripp > < Alana Walsh > < Alberto Errazuriz > < Alexander Hunold > < Alexander Khoo > 5 rows found.
Call the RPAD
function to return last_name
right-padded to length 20 characters with the dot ('.
') character. Use the employees
table and select first five rows.
Command> SELECT FIRST 5 RPAD (last_name,20,'.') FROM employees ORDER BY last_name; < Abel................ > < Ande................ > < Atkinson............ > < Austin.............. > < Baer................ > 5 rows found.