w3resource

Oracle RPAD function

Description

The Oracle RPAD function is used to padding the right side of a string with a specific set of characters. This function is useful for formatting the output of a query.

The string cannot be null. If expr2 not specified then it defaults to a single blank. When expr1 is longer than n, then this function returns the portion of expr1 that fits in n.

Syntax:

RPAD(expr1 , n [, expr2 ])

Parameters:

Name Description Data Types
expr1 Original string. CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB
n A number indicating the total length of the string ( in characters) returned after padding. NUMBER integer or a value that can be implicitly converted to a NUMBER integer.
expr2 String which is used for left padding. CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB

Return Value Type

CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB

Applies to

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Pictorial Presentation

Oracle RPAD function pictorial presentation

Examples: Oracle RPAD function

The following example creates a simple chart of salary amounts by padding a single space with asterisks:

SELECT last_name, RPAD(' ', salary/1000/1, '*') "Salary"
FROM employees
WHERE department_id = 80
ORDER BY last_name, "Salary";

Sample Output:

LAST_NAME               Salary
----------------------------------
Alberto                 ***********
Allan 			********
Alyssa 			*******
Amit 			*****
Charles 		*****
Christopher 		*******
Clara 			*********
Danielle 		********
David 			*****
David 			********
Eleni 			*********
Elizabeth 		******
Ellen 			**********
. . .

Previous: REPLACE
Next: RTRIM



Share this Tutorial / Exercise on : Facebook and Twitter